Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Use Automator to search through folders and find ones with specified missing subfolder.

I'm trying to figure out how to use automator to look through a block of folders (and subfolders) and then list all folders that do not contain a specifically named folder.


Folders are structured as below:


delivery001/20150504/2157x1536

delivery001/20150505

delivery001/20150506

delivery001/20150507/2157x1536

delivery001/20150508


So I'd like to be able to formulate a way to only find the folders that DO NOT contain the '2157x1536' subfolder and create a list of these results if possible?


I've tried multiple ways, but can only get the list to show folders containing that folder and not vice versa! Any ideas?

MacBook Pro, OS X Mountain Lion (10.8.2), 2.2 Ghz i7 Quad Core/8Gb RAM/750GB

Posted on May 13, 2015 3:17 AM

Reply
Question marked as Best reply

Posted on May 13, 2015 4:25 AM

You can do this in Terminal with find and test (using the \! not operator):


find $HOME/Desktop/delivery001 -type d -depth 1 -exec test \! -d "{}/2157x1536" ';' -print


[Note: change $HOME/Desktop/delivery001 to match your directory]


You can put this in Automator:


User uploaded file


The Run Shell Script Action is:


find $1 -type d -depth 1 -exec test \! -d "{}/2157x1536" ';' -print > $HOME/Desktop/missing.txt


and a list of the directories missing 2157x1536 will be written to a file named "missing.txt" on the Desktop.

8 replies
Question marked as Best reply

May 13, 2015 4:25 AM in response to benjamin-mills

You can do this in Terminal with find and test (using the \! not operator):


find $HOME/Desktop/delivery001 -type d -depth 1 -exec test \! -d "{}/2157x1536" ';' -print


[Note: change $HOME/Desktop/delivery001 to match your directory]


You can put this in Automator:


User uploaded file


The Run Shell Script Action is:


find $1 -type d -depth 1 -exec test \! -d "{}/2157x1536" ';' -print > $HOME/Desktop/missing.txt


and a list of the directories missing 2157x1536 will be written to a file named "missing.txt" on the Desktop.

May 13, 2015 5:05 AM in response to Tony T1

Is it possible to just remove the print to text part of the shell script and add a save to text document workflow block after the shell script? Will it contain the correct data??


Is it also possible to amend the depth of subfolders it looks to? For example say in one of the directories contained an extra of level of subfolder, would it be possible to also get it to show those folders and that they're missing a 2157x1536 folder?


Also to advance on what you've sent me so far, using the results created, is there a way to then add in a 2157x1536 folder to all those directories that do not currently contain one?

May 13, 2015 5:18 AM in response to benjamin-mills

benjamin-mills wrote:


Also to advance on that, using the results created, is there a way to then add in a 2157x1536 folder to all those directories that do not currently contain one?


Yes. Just need to add execdir.

For the Run Shell Script Action:

find $1 -type d -depth 1 -exec test \! -d "{}/2157x1536" \; -execdir mkdir "{}/2157x1536" \;

May 14, 2015 5:35 AM in response to benjamin-mills

benjamin-mills wrote:


Thanks so much Tony!


So last but not least.... Say the folders that were missing the 2157x1536 directories contained a bunch of files, would there be a way to move those files into the newly created 2157x1536 folder?


This can be done by adding another Do Shell Script Action with find and -execdir

We also need to use the Set Value of Variable and Get Value of Variable Actions.

Note: This will move all files in the Folders below the selected directory (20150504, 20150505, etc), except .DS_Store to the 2157x1536 Folder:


User uploaded fileUser uploaded file



The new Run Shell Script Action is:


find $1 -type f -depth 2 \! -iname '.DS_Store' -execdir mv "{}" "2157x1536" \;

Use Automator to search through folders and find ones with specified missing subfolder.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.