advertisement
Forums

The Forum is sponsored by 
 

AAPL stock: Click Here

You are currently viewing the Tips and Deals forum
I've got 602 folders, 2 of which are missing a file. How do I find which ones?
Posted by: mikebw
Date: August 29, 2022 10:22AM
It's a PDF of the same name, I can search to find 600 instances of the pdf, but haven't yet figured how to quickly determine which two folders do not have the pdf.

What would you do?
Options:  Reply • Quote
Re: I've got 602 folders, 2 of which are missing a file. How do I find which ones?
Posted by: mattkime
Date: August 29, 2022 10:47AM
Is it the same file content in all the folders?

Otherwise I'd write a script in whichever language you're most comfortable with.



Options:  Reply • Quote
Re: I've got 602 folders, 2 of which are missing a file. How do I find which ones?
Posted by: mikebw
Date: August 29, 2022 11:00AM
Quote
mattkime
Is it the same file content in all the folders?

No, each file is unique.

Quote
matttkime
Otherwise I'd write a script in whichever language you're most comfortable with.

That's not really my forté.

I've seen some info about using Boolean operands in spotlight but I cannot seem to get it down. Basically, searching for folders who do NOT contain the filename, or even the .pdf file type at all.
Options:  Reply • Quote
Re: I've got 602 folders, 2 of which are missing a file. How do I find which ones?
Posted by: TheTominator
Date: August 29, 2022 11:21AM
If your 602 folders are subfolders in the same folder, e.g.

MyRepetitiveFolder contains folders named
001
002
003
004
005
006
006b
006c
2022-03-27
0099
b27

and so on for 602 folders...

and you are looking for a PDF file named document.pdf,

then in the Terminal when in the MyRepetitiveFolder folder type

for d in */ ; do [[ -f $d/document.pdf ]] || echo $d ; done

This will print out the names of the folders that do not have document.pdf.

I have not tested if this will work with folders that have spaces or odd characters in the names.


If the folder structure is more complicated, I think you can get the job done with "find" in the Terminal, but as I am a novice at using find, I haven't explored how to accomplish this.



Edited 1 time(s). Last edit at 08/29/2022 11:23AM by TheTominator.
Options:  Reply • Quote
Re: I've got 602 folders, 2 of which are missing a file. How do I find which ones?
Posted by: mikebw
Date: August 29, 2022 11:34AM
THANK YOU TheTominator! That worked like a charm.
Options:  Reply • Quote
Re: I've got 602 folders, 2 of which are missing a file. How do I find which ones?
Posted by: TheTominator
Date: August 29, 2022 11:36AM
A crude way to use the Terminal's find is

find . -type d -exec ls {}/document.pdf > /dev/null \;


This assumes that you are already 'cd' into the top level directory. This will search all nested subdirectories and report which subdirectories are missing the document.pdf.
A side effect of this expression is that it will always search the current top level directory too.

The "> /dev/null" part is to toss away the usual results of "ls" which is to state that it found the file by printing out the filename. When "ls" doesn't find the specified file, it prints a message to the error channel which is what you see printed for the folders missing the file.
Options:  Reply • Quote
Re: I've got 602 folders, 2 of which are missing a file. How do I find which ones?
Posted by: M A V I C
Date: August 29, 2022 02:53PM
If they were all in the same parent folder, and supposed to be the same size, you could sort by file size and those missing a file would show up together as being smaller. Calculating file size would need to be turned on.




Help MacInTouch: Buy from Amazon? use this link [amazon.com]
Mac News & Info: [macintouch.com] [macnn.com] [tuaw.com]
Mac Benchmarks: [barefeats.com]
Used Mac Stuff [FS/T]: LowEndMac Swap List
Mac Software Updates: [macupdate.com]
Fonts: [dafont.com] [fontspace.com]
Online Computer Store With Mac Support: [macsales.com]
Options:  Reply • Quote
Re: I've got 602 folders, 2 of which are missing a file. How do I find which ones?
Posted by: mikebw
Date: August 29, 2022 03:54PM
Quote
M A V I C
If they were all in the same parent folder, and supposed to be the same size, you could sort by file size and those missing a file would show up together as being smaller. Calculating file size would need to be turned on.

Great idea! In this case every folder would be slightly different in size, and the PDFs small enough not to make a noticeable difference.
Options:  Reply • Quote
Re: I've got 602 folders, 2 of which are missing a file. How do I find which ones?
Posted by: modelamac
Date: August 30, 2022 07:31AM
Could you sort the folders by size? The smallest would be those missing the files.



Ed (modelamac)

I think I will just put an OUT OF ORDER
sticker on my head and call it a day.
Options:  Reply • Quote
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 509
Record Number of Users: 186 on February 20, 2020
Record Number of Guests: 5122 on October 03, 2020