Created
November 28, 2022 14:22
-
-
Save hamaguchi-amago/030f70d7d58987c4ee8121356b375ddc 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 glob | |
import os.path | |
# sub かつ txt | |
print("[1]") | |
for filename in glob.glob("working/**/sub*/**", recursive=True): | |
if filename.endswith(".txt"): | |
print(filename) | |
print() | |
# ディレクトリではない (isfile) | |
print("[2]") | |
for filename in glob.glob("working/**", recursive=True): | |
if os.path.isfile(filename): | |
print(filename) | |
print() | |
# ファイル名を取得する | |
print("[3]") | |
for filename in glob.glob("working/**", recursive=True): | |
if os.path.isfile(filename): | |
basename = os.path.basename(filename) | |
name, ext = os.path.splitext(basename) | |
print(filename) | |
print(name, ext) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ブログで作成しました。
【Python】globを使ってファイルの一覧を取得する
https://neko-py.com/python-glob