Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53831

Re: Help - Python syntax - repeats script through subordinate folders

References <3f4f33ee-c8e7-4154-a817-c74b26b00301@googlegroups.com>
Date 2013-09-08 11:56 +1000
Subject Re: Help - Python syntax - repeats script through subordinate folders
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.147.1378605394.5461.python-list@python.org> (permalink)

Show all headers | View raw


On Sun, Sep 8, 2013 at 11:41 AM, BlueFielder <bluefielder@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Help - Python syntax - repeats  script through subordinate folders BlueFielder <bluefielder@gmail.com> - 2013-09-07 18:41 -0700
  Re: Help - Python syntax - repeats script through subordinate folders Chris Angelico <rosuav@gmail.com> - 2013-09-08 11:56 +1000
    Re: Help - Python syntax - repeats script through subordinate folders BlueFielder <bluefielder@gmail.com> - 2013-09-07 19:52 -0700
      Re: Help - Python syntax - repeats script through subordinate folders BlueFielder <bluefielder@gmail.com> - 2013-09-07 19:59 -0700
        Re: Help - Python syntax - repeats script through subordinate folders Chris Angelico <rosuav@gmail.com> - 2013-09-08 13:01 +1000
          Re: Help - Python syntax - repeats script through subordinate folders BlueFielder <bluefielder@gmail.com> - 2013-09-07 20:09 -0700
            Re: Help - Python syntax - repeats script through subordinate folders Michael Torrie <torriem@gmail.com> - 2013-09-07 21:34 -0600
            Re: Help - Python syntax - repeats script through subordinate folders Chris Angelico <rosuav@gmail.com> - 2013-09-08 13:37 +1000
              Re: Help - Python syntax - repeats script through subordinate folders BlueFielder <bluefielder@gmail.com> - 2013-09-07 20:54 -0700

csiph-web