Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #53830 > unrolled thread
| Started by | BlueFielder <bluefielder@gmail.com> |
|---|---|
| First post | 2013-09-07 18:41 -0700 |
| Last post | 2013-09-07 20:54 -0700 |
| Articles | 9 — 3 participants |
Back to article view | Back to comp.lang.python
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
| From | BlueFielder <bluefielder@gmail.com> |
|---|---|
| Date | 2013-09-07 18:41 -0700 |
| Subject | Help - Python syntax - repeats script through subordinate folders |
| Message-ID | <3f4f33ee-c8e7-4154-a817-c74b26b00301@googlegroups.com> |
I'm NOT a programmer…. but I have a little Python script that converts files, that are in a folder, from one format to another. Script = fxp2aupreset.py I can successfully run it from the command line: 1st, I placed the folder that I named 'ddd' on the desktop so that it's easy to get to. 2. Terminal : cd ~/Desktop/ddd 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. Could someone put this together for me please. Something that I could just copy and paste into Terminal. I would be most grateful. Thank you very much!
[toc] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-09-08 11:56 +1000 |
| Subject | Re: Help - Python syntax - repeats script through subordinate folders |
| Message-ID | <mailman.147.1378605394.5461.python-list@python.org> |
| In reply to | #53830 |
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
[toc] | [prev] | [next] | [standalone]
| From | BlueFielder <bluefielder@gmail.com> |
|---|---|
| Date | 2013-09-07 19:52 -0700 |
| Subject | Re: Help - Python syntax - repeats script through subordinate folders |
| Message-ID | <38324fe2-cbad-4466-a19f-efc0d99f0883@googlegroups.com> |
| In reply to | #53831 |
On Saturday, September 7, 2013 9:56:25 PM UTC-4, Chris Angelico wrote:
> 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
Hi Chris.
Thank you so much for your rely.
Yes…. I am doing this on a Mac OS
>
> 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.
I wish to run the script just once on the parent folder…. and have it run through all the 86 subordinate folders that reside in that parent folder.
> $ 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!
OK I will try that as soon as I can and post the results.
FWIW: I'm not convened with 'tidy' … as I will only being coin this once.
So very kind of you to help.
HT to you sir.
[toc] | [prev] | [next] | [standalone]
| From | BlueFielder <bluefielder@gmail.com> |
|---|---|
| Date | 2013-09-07 19:59 -0700 |
| Subject | Re: Help - Python syntax - repeats script through subordinate folders |
| Message-ID | <21ac62b9-221a-4180-b759-0a8c73c6ef9c@googlegroups.com> |
| In reply to | #53832 |
Failed:
Here is the command with the results:
--------
CiMac:ddd camforx$ $ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata' \;
-bash: $: command not found
----------
With CiMac = HD
ddd = folder on the desktop of user camforx
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-09-08 13:01 +1000 |
| Subject | Re: Help - Python syntax - repeats script through subordinate folders |
| Message-ID | <mailman.148.1378609297.5461.python-list@python.org> |
| In reply to | #53833 |
On Sun, Sep 8, 2013 at 12:59 PM, BlueFielder <bluefielder@gmail.com> wrote:
>
> Failed:
>
> Here is the command with the results:
> --------
>
> CiMac:ddd camforx$ $ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata' \;
> -bash: $: command not found
Oh! Omit the dollar sign, that was representing your prompt :)
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | BlueFielder <bluefielder@gmail.com> |
|---|---|
| Date | 2013-09-07 20:09 -0700 |
| Subject | Re: Help - Python syntax - repeats script through subordinate folders |
| Message-ID | <6291a5d0-ad20-4689-bc1b-570c9e635108@googlegroups.com> |
| In reply to | #53834 |
I 'think' I did as you instructed …. but that too failed. :(
CiMac:ddd camforx$ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata' \;
find: illegal option -- t
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2013-09-07 21:34 -0600 |
| Subject | Re: Help - Python syntax - repeats script through subordinate folders |
| Message-ID | <mailman.151.1378611304.5461.python-list@python.org> |
| In reply to | #53837 |
On 09/07/2013 09:09 PM, BlueFielder wrote:
> I 'think' I did as you instructed …. but that too failed. :(
>
>
> CiMac:ddd camforx$ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata' \;
> find: illegal option -- t
> usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
> find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
Some versions of find require a path first. Try this (all one line):
find . -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./
aumu Alb3 LinP vstdata' \;
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-09-08 13:37 +1000 |
| Subject | Re: Help - Python syntax - repeats script through subordinate folders |
| Message-ID | <mailman.152.1378611439.5461.python-list@python.org> |
| In reply to | #53837 |
On Sun, Sep 8, 2013 at 1:34 PM, Michael Torrie <torriem@gmail.com> wrote:
> On 09/07/2013 09:09 PM, BlueFielder wrote:
>> I 'think' I did as you instructed …. but that too failed. :(
>>
>>
>> CiMac:ddd camforx$ find -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./ aumu Alb3 LinP vstdata' \;
>> find: illegal option -- t
>> usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
>> find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
>
> Some versions of find require a path first. Try this (all one line):
>
> find . -type d -execdir bash -c 'cd {}; python ./fxp2aupreset.py ./
> aumu Alb3 LinP vstdata' \;
Thanks Michael. I'm using GNU find on Debian Linux (or on Ubuntu,
depending on which computer I test on), so I can't be sure what's
different.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | BlueFielder <bluefielder@gmail.com> |
|---|---|
| Date | 2013-09-07 20:54 -0700 |
| Subject | Re: Help - Python syntax - repeats script through subordinate folders |
| Message-ID | <47fcbf3c-4416-4f47-8070-7baad5fa2cc7@googlegroups.com> |
| In reply to | #53839 |
Thanks guys … that too failed. It's late here and I'm bushed. I'll get back to this tomorrow morning. Much appreciated. It's probably important that I point out that I put the file ' fxp2aupreset.py ' in the root directory (ddd) . Just to keep things all together. Again …. I have NO idea how to do any of this. Also …the root folder only contains the .py file and subfolders. The subfolders contain 100's of the files that I wish to convert. If you want to take a look at the last results …. In my DropBox here >> https://dl.dropboxusercontent.com/u/65969526/Results.rtf Good night all, and thank you again.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web