Help - Python syntax - repeats script through subordinate folders

B

BlueFielder

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) andthen 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!
 
C

Chris Angelico

3. Then I run the script from terminal : python ./fxp2aupreset.py ./ aumuAlb3 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
 
B

BlueFielder

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 runthrough 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.
 
B

BlueFielder

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]
 
M

Michael Torrie

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' \;
 
C

Chris Angelico

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
 
B

BlueFielder

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top