1

I've made a little script so I can select some files in Explorer (on Windows XP), right click, and Sendto. The script works fine for up to 20 files, but fails when 21 or more files are selected. Why & how can I fix this?

:Loop
If "%~dpn1"=="" Goto :EOF
convert "%~dpn1.jpg" "%~dpn1_dvr_hires.tif"
convert "%~dpn1.jpg" -scale 150 -density 72 "%~dpn1_dvr_hires_renamed.jpg"
Shift 
Goto Loop

When I drag & drop or use the sendto menu: <20 files, and the command runs fine as expected, but >20 and I get a "Windows cannot access the specified device, path, or file. You may not have the appropriate permission to access the item." I have checked & changed the permissions, the permissions do not seem to be the problem.

Mica
  • 18,501
  • 6
  • 46
  • 43
  • When you say it fails, what's the nature of the failure? – Mark Oct 23 '12 at 17:00
  • @Mark I've added some details to my post. >20 files, I get a "cannot access file" error! :-\ – Mica Oct 23 '12 at 18:18
  • I think it may still be an invalid character issue. I just tested with way more then 20 files and it worked fine. – aphoria Oct 23 '12 at 18:37
  • Looks like it is the maximum line length of 8191 bytes. I move the dir of images into C:\ and was able to process about 30 files. :-| – Mica Oct 23 '12 at 18:49

1 Answers1

3

Send To uses the same mechanism as drag and drop. A command line is built incorporating the full path to each file name as arguments. There is a maximum line length of 8191 bytes. I suppose it is possible that you are reaching that limit with only 21 files, but it is highly unlikely.

The more likely scenario is you may be running into file names that contain & and/or ^ characters. There is a bug with "drag and drop" / "Send To" that fails to properly quote file names containing & or ^. It is frustrating, because names containing space are properly quoted.

See “Droplet” batch script - filenames containing ampersands for more information and a possible solution.

Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390
  • Hi thanks for the answer! I've had a look at your solution, but having just renamed all files by hand, there are no ^ or & in the file names. I doubt it's the 8191 bytes length. I used the script that shows the command (from your link) but I get exactly the same results: <20 files, and the command runs fine as expected, but >20 and I get a "Windows cannot access the specified device, path, or file. You may not have the appropriate permission to access the item." – Mica Oct 23 '12 at 18:07
  • @Mica - Very interesting, and thanks for the feedback. Unfortunately I am at a loss as to what could be causing the problem. – dbenham Oct 23 '12 at 18:17
  • Me too! Appreciate the quick response tho! Nothing makes me pine for a proper *nix shell more than something like this! – Mica Oct 23 '12 at 18:22
  • Bleh! I lied. Moved the whole folder to C:\ from the Desktop, and I can now process about 30 files. Looks like is the char limit :( – Mica Oct 23 '12 at 18:48