foxidrive wrote:Antonio, your command should not have the path added to the target:
Code: Select all
for %%a in ("%pathy%\*.png") do COPY /Y "%startfile%" "%%a"
(I noticed that myself, surprisingly

Ah, I see. For one thing, I had no reason to define %%a as the file without the path, then tie it back into the path later. You're also right that I misunderstood the difference between for and for /f and didn't realize it was treating %%a as a string of tokens with space delimiters.
Antonio, huge thanks for including an actual answer for context instead of just the boilerplate RTFM reply. I haven't had to code anything in years, and I doubt it will come up again any time soon - I just needed this specific script to do its job. The "why" also makes a lot more sense with a real-world example.
Couple other replies:
Squashman wrote:I agree Antonio.
Still think this code is dangerous. I see no reason to overwrite a bunch of files with the same data.
Why would I write a script to accomplish this if there wasn't a need? I of course include user prompts confirming the sourcefile and target folder before allowing the batch to run, and am hugely careful to disclaim what this does and why. As far as the "dangerous" for /f loop itself, I lifted it from someone who I knew was able to use it for something nearly identical to my intended purpose (I only had to revise the "do" section) and used echo to carefully test what it intended to do before actually adding the copy section. Incidentally, the fact that the end-user has a backup of the target files is implicit here. They've extracted them from a zip file.
If you must know, when creating an icon theme for a jailbroken iOS device, each target icon to theme contains a folder full of multiple files, sometimes upwards of 20 or more, the only difference between each file being their resolution, which long story short has no bearing on an icon theme other than filesize (I'll probably use a command-line tool to read and account for the resolution issue to save a little space at some point, but that's a topic for another day). The quickest solution, then, is to make your newly themed image then make copies of it to replace everything in an icon's folder. I can do that one at a time through photoshop, but why? Anyway, hopefully this satisfies your curiosity a bit.