250x250
Link
λ‚˜μ˜ GitHub Contribution κ·Έλž˜ν”„
Loading data ...
Notice
Recent Posts
Recent Comments
관리 메뉴

Data Science LAB

[Python] ν•˜μœ„λ””λ ‰ν† λ¦¬ 검색 λ³Έλ¬Έ

🐍 Python/기초

[Python] ν•˜μœ„λ””λ ‰ν† λ¦¬ 검색

γ…… γ…œ γ…” γ…‡ 2022. 5. 3. 22:37
728x90

μ§€λ‚œ ν¬μŠ€νŒ…μ—μ„œλŠ” 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 λ“±λ“± λ‹€μ–‘ν•œ 파일 ν˜•μ‹μ„ 뢈러올 수 μžˆλ‹€. 

728x90
Comments