Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Click here to return to the 'Create Placeholders for downloaded files' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create Placeholders for downloaded files
Authored by: Magnus Dredd on Mar 13, '11 09:01:04PM

There are a substantial number of files containing a "1" in my download directory which haven't been deleted.

To be sure however, I just tried a test set again... Repeatedly...

You're not completely incorrect, but almost.

List of files (Every single one contain a "1"):
Getting Started With Oracle Solaris 11 Express Guide 820-7799.pdf
M3291 InstallGuide.pdf
hdama bios

The first part of the script
find . -exec mdls -name kMDItemFSLabel {} \; -exec mdls -name kMDItemFSName {} \;
Outputs this:

kMDItemFSLabel = 1
kMDItemFSName = "file-1.pdf"
kMDItemFSLabel = 0
kMDItemFSName = "Getting Started With Oracle Solaris 11 Express Guide 820-7799.pdf"
kMDItemFSLabel = 0
kMDItemFSName = "hdama bios"
kMDItemFSLabel = 0
kMDItemFSName = "information_supplement_11.3.pdf"
kMDItemFSLabel = 0
kMDItemFSName = "M3291 InstallGuide.pdf"
kMDItemFSLabel = 0
kMDItemFSName = "Prioritized_Approach_PCI_DSS_1_2.pdf"

find . -exec mdls -name kMDItemFSLabel {} \; -exec mdls -name kMDItemFSName {} \; | awk -F " = " ' $2 ~ /1/{ getline; print $2 }' | sed -ne '/^".*/p' | awk '{ print "rm "$0"; touch "$0 }'

Outputs this:
rm "file-1.pdf"; touch "file-1.pdf"
rm "Prioritized_Approach_PCI_DSS_1_2.pdf"; touch "Prioritized_Approach_PCI_DSS_1_2.pdf"

All of the files contain a "1".
One file was "grey"
One file contained a "1" and it was the last one found!!!

When the script finds a "1" in the part of a line after the " = " it then grabs the <b>next line</b> and ignores the current one.

So if it matches a "1" in a file name:
kMDItemFSName = "hdama bios"
It gets the next line which is:
kMDItemFSLabel = 0
Of which it would try to delete "0", except that I use sed to filter any line not containing a `"` (quote)

The problem is that if it matches the file name on the last line.... "getline" cannot get the next line and returns the current one.

The bottom line is that your change is a good idea.

[ Reply to This | # ]
Create Placeholders for downloaded files
Authored by: vczilla on Mar 15, '11 04:21:04AM

Yes sorry if that wasn't clear my comment was only on the $2 ~ /1/ part that matches every second field containing a '1' (so it matches filenames containing a '1' but it also matches kMDItemFSLabel = 1 ) not on the overal effect of your script. Glad you liked the fix.

[ Reply to This | # ]