I want to detect a specific folder (For example: D:\Fldr), then search through its sub-folders, extracting all text files' names inside of those sub-folders. I wrote this:
import os
Prev_WorkFolder = os.getcwd()
FileNameLst = []
for _Root, _Folder, _File in os.walk('D:'):
if _Folder == 'Fldr':
os.chdir ('/Fldr')
for FileName in _File:
if FileName.endswith (('.txt')):
FileNameLst.append (FileName)
print (FileNameLst)
os.chdir (Prev_WorkFolder)
This didn't give out neither any result nor any errors(as I expected). I've read several threads in SOF about how to deal with files and folders in Python, but I can't put all those into action.
PS:
Another problem is that I manually set it to go for drive D: actually I need it to automatically locate that folder (Fldr) on any drive.