Help - Python syntax - repeats script through subordinate folders

Chris Angelico rosuav at gmail.com
Sat Sep 7 21:56:25 EDT 2013


On Sun, Sep 8, 2013 at 11:41 AM, BlueFielder <bluefielder at gmail.com> wrote:
> 3. Then I run the script from terminal : python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata
>
> It executes fine and does it's job.
>
> BUT… I have per 7600 files that are segregated into 86 folders.
> I want to keep this folder structure.
>
> So, What I need the script to do is to start at the parent folder (ddd) and then go through each subordinate (child) folder and perform its task on all files.
>
> I found this syntax on the web that is somehow supposed to do what I need:
>
> for /r %a in (*.fxp) do example.py "%a"
>
> BUT … I have no idea how to combine the syntax.

Your initial command and path suggest you're on a Unix-like system
(these days that most likely means either Linux or Mac OS), but the
FOR command at the end is a Windows command, so that's not going to
work. However, Unix does have a find command, so that should work for
you.

Do you need to run your script once for each file, or once for each
directory? Based on your use of "for /r", I'm thinking once per
directory.

$ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./
aumu Alb3 LinP vstdata' \;

I'm sure there's a tidier way to do it, but this should work!

ChrisA



More information about the Python-list mailing list