1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| folder : file1.txt, file2.txt, file101.txt, file102.txt, file_a.txt, file_b.txt, file1.jpg, file2.jpg folder/sub_folder : subfile1.txt, subfile2.txt folder/sub_folder/sub/sub2 : sub2.txt
import glob
output = glob.glob('folder/*.txt') print(output) ['folder/file1.txt', 'folder/file102.txt', 'folder/file2.txt', 'folder/file_a.txt', 'folder/file_b.txt']
output = glob.glob('folder/file?.*') print(output) ['folder/file1.bmp', 'folder/file1.txt', 'folder/file2.bmp', 'folder/file2.txt', 'folder/file_a.txt', 'folder/file_b.txt']
output = glob.glob('folder/**xt') print(output) ['folder/file1.txt', 'folder/file102.txt', 'folder/file2.txt', 'folder/file_a.txt', 'folder/file_b.txt', 'folder/file12.txt]
# '[]'를 사용하여 정규표현식으로 사용도 가능합니다. output = glob.glob('folder/file[0-9]*.txt') print(output) ['folder/file1.txt', 'folder/file102.txt', 'folder/file2.txt']
|