상세 컨텐츠

본문 제목

glob module

파이썬

by simstealer 2021. 12. 8. 17:27

본문

특정 디렉토리에 있는 모든 파일을 검색할때 사용.

 

(리눅스 시스템의 예)

>>> import glob
>>> glob.glob('/root/bin/*.sh')
['/root/bin/telnet.sh', '/root/bin/searchsploit.sh', '/root/bin/ssh_crack_cmd.sh', '/root/bin/ftp.sh', '/root/bin/copy.sh', '/root/bin/onesixtyone.sh', '/root/bin/ssh.sh', '/root/bin/ping.sh', '/root/bin/pycharm.sh', '/root/bin/banner.sh', '/root/bin/test.sh', '/root/bin/cmd.sh', '/root/bin/dnmap.sh', '/root/bin/route.sh']
>>> shellscriptlist = glob.glob('/root/bin/*.sh')
>>> shellscriptlist
['/root/bin/telnet.sh', '/root/bin/searchsploit.sh', '/root/bin/ssh_crack_cmd.sh', '/root/bin/ftp.sh', '/root/bin/copy.sh', '/root/bin/onesixtyone.sh', '/root/bin/ssh.sh', '/root/bin/ping.sh', '/root/bin/pycharm.sh', '/root/bin/banner.sh', '/root/bin/test.sh', '/root/bin/cmd.sh', '/root/bin/dnmap.sh', '/root/bin/route.sh']

 

(윈도우 시스템의 예)

>>> glob.glob("c:\*")
['c:\\$AV_ASW', 'c:\\$Recycle.Bin', 'c:\\$SysReset', 'c:\\bootTel.dat', 'c:\\Config.Msi', 'c:\\Documents and Settings', 'c:\\hiberfil.sys', 'c:\\Intel', 'c:\\MSOCache', 'c:\\pagefile.sys', 'c:\\PerfLogs', 'c:\\Program Files', 'c:\\Program Files (x86)', 'c:\\ProgramData', 'c:\\Python27', 'c:\\Recovery', 'c:\\swapfile.sys', 'c:\\System Volume Information', 'c:\\Temp', 'c:\\Users', 'c:\\Windows', 'c:\\Windows10Upgrade']

'파이썬' 카테고리의 다른 글

re module  (0) 2021.12.17
time module  (0) 2021.12.17
os module  (0) 2021.12.08
sys module  (0) 2021.12.08
주요 내장 함수 간단 정리  (0) 2021.12.03

관련글 더보기

댓글 영역