■ 参考 : pythonのosライブラリのos.listdir()で格納したファイル名の順番の仕組みがわからない。
とかすると、hogeの中身の順番がめちゃくちゃ・・・なのでソートする必要がある
■ 参考 : Pythonでファイル名・ディレクトリ名の一覧をリストで取得
# pathにディレクトリ名を入れる
files = os.listdir(path)
files = sorted(files)
hoge = [f for f in files if os.path.isfile(os.path.join(path, f))]
hoge = sorted(hoge)
files = os.listdir(path)
files = sorted(files)
hoge = [f for f in files if os.path.isfile(os.path.join(path, f))]
hoge = sorted(hoge)
ワイルドカードを使ったlsをしたい
globを使えば良い
■ 参考 : Pythonでフォルダ内のファイルリストを取得する
import glob
ls_result = glob.glob("./*.txt")
ls_result = glob.glob("./*.txt")
ファイル名から拡張子を消したいとき
filename_no_extension = os.path.splitext(filename)[0]
ランキング参加中です
↓クリックしていただけると嬉しいです〜