[파이썬, Python] 현재 폴더의 파일 리스트 출력하기 예제 (dir /w)


[filelist.py]

#!/usr/bin/python

import os.path


folder = os.getcwd()

print 'folder: %s' % folder

for filename in os.listdir(folder):

print filename


exit(0)


실행 결과:

D:\mytool>python filelist.py

folder: D:\mytool

filelist.py

filelist1.py



[filelist1.py]

#!/usr/bin/python

import os.path


folder = os.getcwd()

print 'folder: %s' % folder

for filename in os.listdir(folder):

fullname = os.path.join(folder,filename)

print fullname


exit(0)


실행 결과:

D:\mytool>python filelist1.py

folder: D:\mytool

D:\mytool\filelist.py

D:\mytool\filelist1.py



fileList.py

fileList1.py


반응형

+ Recent posts