LoginSignup
2
1

More than 1 year has passed since last update.

Pythonでフォルダのファイル名を小文字(大文字)にする方法

Posted at

フォルダに格納されているファイルが大文字小文字混在のファイル名だったので、これを小文字に統一したくPythonでちょこっとプログラムをかいたのでメモ。

import os     # OS操作
import glob   # パスのパターン(ワイルドカードなど)を使用するため

path = './cards/*.png' # cardsフォルダ内のpngファイルを指定

# パス指定のファイル名を取得して出力してみる
file_list = glob.glob(path)
print(file_list)

for file in file_list:
  # ファイル名を大文字→小文字変換(大文字変換の時はupper()を使用)
  os.rename(file, file.lower())

# ファイル名が変更されているか確認
file_list = glob.glob(path)
print(file_list)

悩み

小文字の「png」と大文字の「PNG」を両方取得するにはどうしたらいいんだろう?誰かPythonの賢者教えて。

参考

2
1
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1