Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230
I used SACAD script to download album covers for my music collection which was successful for over 1000 albums but failed for a lot of more obscure ones. In each directory the cover is saved as cover.png .
I want to copy a .directory file to each directory containing cover.png so the image will replace the directory default image in Dolphin. The .directory file works for that and contains -
How can I copy that file to each directory containing cover.png but not to those that don't? I can use this to copy to all directories but not sure how to make it conditional.
~/test$ find . -type f -name cover.png -print | while read d; do target=\"$(dirname "$d")\";cp ~/temp/.directory $target/; done
cp: cannot create regular file '"./dir2"/': No such file or directory
cp: cannot create regular file '"./dir3/subdir1"/': No such file or directory
This has me baffled. Running the exact cp command as output with echo works as expected.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”Remember toBACKUP!
Hmm. I must admit I didn’t test actual copying, just a few contortions to output the right looking echo string...
Dunno why either and can’t currently test.
Like @dilberts_left_nut, I don't have time to debug. However, I did notice that the error message includes embedded quotes. That is, the quotes are part of the filename (not good).
cp: cannot create regular file '"./dir2"/': No such file or directory
cp: cannot create regular file '"./dir3/subdir1"/': No such file or directory
That means we should take a look at the quotes. Glancing at the script, the embedded double quotes looks problematic. I should have a little more time before bed and will take a look then unless someone else beats me to it.
Last edited by neuraleskimo on 2019-04-11 01:32, edited 1 time in total.
I had added the extra code to include the quotes in the $target variable, but looks like the expansion of the quoted $d during accounts for any space where copy/paste from the echo output wouldn’t.
You didn’t say if your dirnames had spaces, bu my music library definitely does.
You're right dln, I didn't test for spaces and they cause it to fail. Double quotes around the variable in neuraleskimo's example code seems to work OK:
~/test$ find . -type f -name cover.png -print | while read d; do cp ~/temp/.directory "$(dirname "$d")"/; done
Combine the greatest minds on FDN and the greatest bash n00b (me) and we get there in the end. Thank you both!
Now to try it on my actual music collection. Soon...
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”Remember toBACKUP!
Worked quite well on ~1100 albums along with SACAD. I still had to to recheck manually as SACAD made a small number of dodgy album art matches but overall it saved a lot of time, even allowing for how long it took to work out the right command. And I learned a bit more about BASH on the way! Double win.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”Remember toBACKUP!