python script
i am in the root of directory.
E:
i want to go into next directory and sub directory a with a input"directory name"
- like first go into E:\zimi
- and then into E:\zimi\files then apply operation in current directory of E:\zimi\files
navigate.py first_directory_name second_directory_name and do rest of operation that is already done directory name given as input. sub directory name is also given as name. after navigating into directory
1 Answer 1
Would os.walk() be the answer you're looking for?
i.e. assuming you're already in e:\
for dirpath, dirnames, filenames in os.walk("."):
<your code here>
This would traverse the directories in e:
if you wish to limit only to zimi, just:
os.chdir("zimi")
for dirpath, dirnames, filenames in os.walk("."):
<your code here>
answered Jun 26, 2020 at 0:56
ewokx
2,4413 gold badges20 silver badges45 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py
os.chdir()