Last active
December 9, 2022 03:13
-
-
Save NobukazuHanada/cb90d4757a2819e2adf45d9e87b0de6d 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 | |
# リネーム後のラベル | |
label = "label"; | |
# 指定されたフォルダのパス | |
folder_path = 'C:\\Users\\example\\Documents\\files' | |
# フォルダ内のファイル名を取得 | |
file_names = os.listdir(folder_path) | |
# ファイル名を連番付けして、変換 | |
for i, file_name in enumerate(file_names): | |
# 拡張子の取得 | |
splitext = os.path.splitext(file_name) | |
extension = splitext[len(splitext) - 1] | |
# 変換後のファイル名 | |
new_file_name = f'{label}_{i}.{extension}' | |
# ファイルをリネーム | |
os.rename( | |
os.path.join(folder_path, file_name), | |
os.path.join(folder_path, new_file_name) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方
ソースコードの以下の部分を適切に変更してください。
以下のコマンドで実行
python RenamingfilesInFolder.py