9/17/2018

python get file list in directory

from os import listdir
from os.path import isfile, join
mypath = "./customer_sample"
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
print(onlyfiles)

result
['._s1.pdf', 's2.pdf', '._s2.pdf', '._s7.pdf', 's8.pdf', '._s8.pdf', '._s9.pdf', 's10.pdf', '._s10.pdf', 's1_p0.jpg', 's9.pdf', '._s1_p0.jpg', '._s4.pdf', 's5.pdf', '._s5.pdf', 's6.pdf', '._s6.pdf', 's7.pdf', '._s3.pdf', 's4.pdf', 's2_p0.jpg', 's2_p1.jpg', 's3_p0.jpg', 's3.pdf', 's3_p1.jpg', 's3_p2.jpg', 's1.pdf', 's3_p3.jpg']

No comments:

Post a Comment