|
|||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
#1 |
|
Prospect
Join Date: Feb 2010
Posts: 6
|
scripting help for creating new folders within a bunch of folders
I have a folder structure as follows all items>item name>item colour>files.
Now in this item colour folder are 2 files, a large sized image and a thumbnail version of that image. I need to create a folder in here called thumbnail and move the thumbnail image into it. Can I do this with automator or applescript? I have maybe about 30 item name folders with various amounts of folders within each of those. If I was to say what it was in code terms it'd be for every folder in all items,open folder then go in every folder in here and create a directory called thumbnail and move the file named closeupTN.jpg into here. |
|
|
|
|
|
#2 |
|
MVP
Join Date: Aug 2009
Posts: 1,119
|
A simple one-liner would do the trick.
Code:
find /base/directory -name '*TN.jpg' -exec cp {} /some/place/where/thumbs/are/stored/ \;
|
|
|
|
|
|
#3 | |||||||||||||||||||||||
|
Prospect
Join Date: Feb 2010
Posts: 6
|
Thanks for this, problem is the pathname will change all the time, as I need a thumbanaill folder in each folder where the files are. I've attached a screenshot of my directory layout for clarity's sake. For each of the first folders, open, then for each of the second folders, open and create a folder called thumbnail and move closeupTN.jpg into it. Last edited by nicolanicola; 03-05-2012 at 10:58 AM. |
|||||||||||||||||||||||
|
|
|
|
|
#4 |
|
MVP
Join Date: Aug 2009
Posts: 1,119
|
Find will traverse all subfolders searching for files.
|
|
|
|
|
|
#5 |
|
Prospect
Join Date: Feb 2010
Posts: 6
|
Is there a 'this' feature in this code? In which case it could be the above code but instead of the path make reference to current directory,or store the create directory path in a variable and then use that variable? I'm a php, actionscript and javascript programmer, so not sure if these coding practices are available for apple scripting.
|
|
|
|
|
|
#6 | |||||||||||||||||||||||
|
Prospect
Join Date: Feb 2010
Posts: 6
|
Yes, but the second part of the code where you've got /some/place/where/thumbs/are/stored/ that isn't static, is depends on the current folder we are in |
|||||||||||||||||||||||
|
|
|
|
|
#7 | |||||||||||||||||||||||
|
MVP
Join Date: Aug 2009
Posts: 1,119
|
Read the find man page. Code:
find $SEARCHPATH -name '*TN.jpg' Code:
find . -name '*TN.jpg' |
|||||||||||||||||||||||
|
|
|
|
|
#8 |
|
MVP
Join Date: Apr 2008
Location: Berkeley CA USA
Posts: 1,009
|
Yes, there is a 'this' feature. Use -execdir instead of -exec.
If I understand you correctly, you want to search recursively through the folder hierarchy rooted at some starting point, and wherever you find a thumbnail in the same subfolder as the JPEG that it's a thumbnail of, you want to move it (not copy it) one level deeper into the folder hierarchy, into a (possibly new) subfolder named 'thumbnail'. Thus, if you start with the structure: . start/ . . jacket/ . . . red/ . . . . big.jpg . . . . bigTN.jpg . . . . small.jpg . . . . smallTN.jpg . . vest/ . . . pink/ . . . . double.jpg . . . . doubleTN.jpg . . . . single.jpg . . . . thumbnail/ . . . . . singleTN.jpg then you want to end up with . start/ . . jacket/ . . . red/ . . . . big.jpg . . . . small.jpg . . . . thumbnail/ <== new folder . . . . . bigTN.jpg <== moved . . . . . smallTN.jpg <== moved . . vest/ . . . pink/ . . . . double.jpg . . . . single.jpg . . . . thumbnail/ <== existing folder . . . . . doubleTN.jpg <== moved . . . . . singleTN.jpg <== not moved As a matter of expediency, instead of testing if the full-size picture is adjacent to a putative thumbnail, I'll use the easier test: a file is a thumbnail that needs to be moved if its name matches *TN.jpg, and it is not already nested in a folder named thumbnail. Code:
find starting/folder -not \( -type d -iname thumbnail -prune \) -name '*TN.jpg' -execdir mkdir -p thumbnail \; -execdir mv {} thumbnail \;
. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|