2015-07-12

Perl one-liner: files in this directory also in that directory?

It's been too long since I've used Perl. But anyway...

Problem: I copied files from one folder to another folder manually. Are any files missing?

In the below example "." is the single source folder and "../vegetables.xcassets" is the parent folder of various destination folders.

perl -e 'opendir(D,".");@f=grep{/jpg$/}readdir(D);for $i (@f){@g = glob qq("../vegetables.xcassets/*/$i"); $m="Not $i"; if (-f $g[0]) {$m="OK"}; print "$m $g[0]\n";}'

Sample output:

OK ../vegetables.xcassets/oregano_large.imageset/oregano_large.jpg
Not oregano_large@2x.jpg 
OK ../vegetables.xcassets/oregano_small.imageset/oregano_small.jpg
OK ../vegetables.xcassets/oregano_small.imageset/oregano_small@2x.jpg

Here you can see I forgot to copy oregano_large@2x.jpg.

I used Perl because I forgot how awful shell handles spaces in file names, and I tried to do it that way first. I realize my example output does not contain spaces in the file names, but you don't want to see the listing all the way down to "summer squash".

If you are asking why did I not automate the copy of the files, it is because the copy happened with Xcode, and I needed its internal XML configuration mangling to happen at the same time.

No comments:

Post a Comment