Skip to content

Instantly share code, notes, and snippets.

@and2long
Created January 12, 2022 06:06
Show Gist options
  • Save and2long/2d6121f98f9964cda94512dddee8642d to your computer and use it in GitHub Desktop.
Save and2long/2d6121f98f9964cda94512dddee8642d to your computer and use it in GitHub Desktop.
重命名当前文件夹下的所有文件。
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