I am new to Python and I am using it to do some data analysis.
My problem is the following: I have a directory with many subdirectories, each one of which contains a large number of data files.
I already wrote a Python script which, when executed in one of those subdirectories, performs the data analysis and writes it on a output file. The script includes some shell commands that I call using os.system()
, so I have to "be" in one of the subdirectories for it to work.
How can I write a function that automatically:
- Moves into the first subdirectory
- Executes the script
- Goes back to the parent directory and moves to the next subdirectory
I guess that this could be done in some way using os.walk()
but I didn't really understand how it works.
PS I am aware of the existence of this post but it doesn't solve my problem.
PPS Maybe I should point out that my function does not take the directory name as argument. Actually it takes no argument.