0

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"

  1. like first go into E:\zimi
  2. 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

2
  • use os.chdir() Commented Jun 25, 2020 at 22:29
  • to use os.chdir() next directory path is necessary which is unknown. Commented Jun 25, 2020 at 22:41

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.