I have a main folder named "simulations". In this folder I have 250 different folders named with year-month-day as: "19902010" "20040512" etc... These dates are random without any specific pattern but always in the form "year-month-day". In each "year-month-day" folder I have a folder named "outfiles" in which are contained the files that I have to change automatically. How can I run this automatically? Hope to have a reply!! Thanks in advance! Silvia
Asked
Active
Viewed 4,776 times
1 Answers
2
If you want to run your Python script (let me call it myScript.py) on each *.grd file in all subfolders (recursively) of a given folder, then find is the right command to do it:
find . -name '*.grd' -exec python myScript.py {} \;
This command recursively finds each file in the given path1 with the name matching *.grd and calls python myScript.py <found .grd file>2 for each found file. You can test this by adding echo right after -exec, then it will just print the commands.
1 I used . in my example and you can use it, too, if you cd to the specified folder first. Otherwise, you can use any appropriate relative or absolute path here.
2 If your script is executable and has the correct shebang, you can leave out python and call myScript.py directly.
See also
Melebius
- 11,750