Created
January 12, 2022 06:06
-
-
Save and2long/2d6121f98f9964cda94512dddee8642d to your computer and use it in GitHub Desktop.
重命名当前文件夹下的所有文件。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
# 重命名当前文件夹下的所有文件。 | |
path = os.path.dirname(os.path.realpath(__file__)) | |
print(path) | |
onlyfiles = [ | |
f for f in os.listdir(path) if os.path.isfile(os.path.join(path, f)) and not f.startswith(".") | |
] | |
for f in onlyfiles: | |
if "]" in f: | |
print(f.split("]")[1]) | |
os.rename(os.path.join(path, f), os.path.join(path, f.split("]")[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment