[Python] νμλλ ν 리 κ²μ
μ§λ ν¬μ€ν μμλ globλ₯Ό μ¬μ©νμ¬ λͺ¨λ νμ λλ ν 리μ νμΌμ λΆλ¬μμλ€.
2022.04.13 - ν΄λ μμ νμΌ νλ²μ λΆλ¬μ€κΈ°
ν΄λ μμ νμΌ νλ²μ λΆλ¬μ€κΈ°
ν΄λμμ μ‘΄μ¬νλ μ¬λ¬ νμΌμ νλ²μ λΆλ¬μ€κΈ° import glob folders = glob.glob('ν΄λκ²½λ‘') ν΄λ μμ μ‘΄μ¬νλ λͺ¨λ ν΄λμ νμΌμ νλ²μ λΆλ¬μ€κΈ° folders = ('첫λ²μ§Έ ν΄λ κ²½λ‘\*') ν΄λ μμ νμΌ μ€
suhye.tistory.com
μ΄λ² ν¬μ€ν μμλ osλͺ¨λμ μ¬μ©νμ¬ λͺ¨λ νμ λλ ν 리μ νμΌμ λΆλ¬μ€λ €κ³ νλ€.
1. λͺ¨λ νμ ν΄λ 리μ€νΈ λΆλ¬μ€κΈ°
import os
dir_path = "μ°Ύκ³ μνλ κ²½λ‘"
for (root, directories, files) in os.walk(dir_path):
for directory in directories:
d_path = os.path.join(root, directory)
print(d_path)
2. λͺ¨λ νμ νμΌ λ¦¬μ€νΈ λΆλ¬μ€κΈ°
for (root, directories, files) in os.walk(dir_path):
for file in files:
file_path = os.path.join(root, file)
print(file_path)
3. νΉμ νμμ νμΌ λΆλ¬μ€κΈ°
for (root, directories, files) in os.walk(dir_path):
for file in files:
if '.json' in file:
file_path = os.path.join(root, file)
print(file_path)
μ΅κ·Ό κ°μ₯ λ§μ΄ μ¬μ©νλ νμΌμ νμμ΄ jsonμ΄κΈ° λλ¬Έμ νμ₯μκ° jsonμΈ μ½λλ₯Ό μμ±νλ€.
csv, txt λ±λ± λ€μν νμΌ νμμ λΆλ¬μ¬ μ μλ€.