1import os
2
3files = os.listdir('.')
4print(files)
5for file in files:
6 # do something
7
1import os
2def fn(): # 1.Get file names from directory
3 file_list=os.listdir(r"C:\Users")
4 print (file_list)
5
6 #2.To rename files
7fn()
1from os import listdir
2from os.path import isfile, join
3onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
1 import os
2 arr = os.listdir()
3 print(arr)
4
5 >>> ['$RECYCLE.BIN', 'work.txt', '3ebooks.txt', 'documents']
6