# Batch File Problem



## bonacker (Sep 16, 2011)

I wanted to add to the Windows "Sendto" context menu some external drives, but when I added them by putting shortcuts to them in the Sendto folder, the context menu was slow to popup, because it waited for all the networked drives to be available which often takes a long time.

To get around the delay, I got the idea of putting shortcuts to local batch files in the Sendto folder with the batch files copying the highlighted files to the cloud. 

This little batch file works well:

copy %1 O:\dropboxbu

Except for this: When I highlight several files and right click them and select the sendto shortcut to the above .bat, it only sends one file.

I can't find anything online that will work. I played around with copy %1* etc. but nothing works.

Is there a way to write the batch file to get all the selected files to copy? 

I thought if I copied all the selected files to the clipboard I might then run a .bat that would paste the clipboard to the network drive, but I can't find anything for a clipboard environment variable in DOS. 

Iam using cmd in XP. I know it's not really DOS, but it seems to work like DOS. Thanks for any help.


----------



## Ent (Apr 11, 2009)

You could try checking through the parameters of the batch script in a loop, as described in this article under the heading "Shift".
http://www.robvanderwoude.com/parameters.php

An alternative would be to use a different scripting language, such as VBS, to accomplish the same task.


----------



## Squashman (Apr 4, 2003)

Ent has you pointed in the right direction. When you drag and drop multiple files onto a batch file each file becomes its own separate argument on the cmd line. So the 2nd file becomes %2 and so on. I do drag and drop for most of my batch files these days.


----------



## bonacker (Sep 16, 2011)

Thank you to both Ent and Squashman. Yes, exactly, Ent got me heading in the right direction. I realized right after I looked at his link that I needed a line for each selected file and came up with this:
_____________________
copy %1 O:\dropboxDoc 
REM Where O is "Otixo" a webdav interface to Dropbox.
IF NOT EXIST %2 "GOTO end" 
copy %2 O:\dropboxDoc 
IF NOT EXIST %3 "GOTO end"

REM continues %3-%8 then

copy %9 O:\dropboxDoc 
IF EXIST %9 "GOTO end" 
echo you shouldn't see this > c:\SendToBats\Report.txt 2>&1
:end
exit
_____________________

However, in that linked page http://www.robvanderwoude.com/parameters.php , I didn't understand how to add more than 9 files. I saw how "shift" should enable more, but I can't quite see how to do it.

The batch files, unlike Windows using the Webdrive service for Webdav, do not automatically mount the network drives following the copy command. When I added a line to the batch file to mount the drive (which works as a Windows shortcut) start /min /wait "C:\Progra~1\WebDrive\webdrive.exe" /s:"dropboxDoc" , it didn't work because the /s was interpreted as a DOS switch, not a Webdrive one. Is there a way to make cmd see it as a Webdrive switch? I tried various quote possibilities. I need to use Webdrive, not net use, because XP won't mount SSL webdavs.

Thanks again for the help. Much appreciated.


----------



## Squashman (Apr 4, 2003)

You are using the GOTO command which is what you need to use in this instance in combination with the SHIFT and IF statement to see if you still have files to copy. So if you put a label before your copy command and the SHIFT command after your copy command and then an IF statement to check to see if %1 is now blank, and if it isn't GOTO your label to loop back to your copy command.

You don't necessarily need to use the START command to mount your DropBox drive. You can just do this.

```
"C:\Progra~1\WebDrive\webdrive.exe" /s:"dropboxDoc"
```
But the problem with your start command is you don't have the syntax correct. You are missing a set of double quotes.

```
start "" /min /wait "C:\Progra~1\WebDrive\webdrive.exe" /s:"dropboxDoc"
```
The set of double quotes with nothing in between it is the TITLE. Without that it was interpreting the Quotes around your executable path as the TITLE.


----------



## bonacker (Sep 16, 2011)

So with the help of the above posters, I got this working (almost) perfectly. Thanks a lot.
--------------
IF NOT EXIST o:\NUL start "" /min /wait "C:\Progra~1\WebDrive\webdrive.exe" /s:"OtixoDrop"

:ANOTHER
IF [%1]==[] GOTO NOMORE
copy %1 o:\docs
SHIFT
GOTO ANOTHER
:NOMORE
exit
--------------
I did encounter a strange problem. It will only copy a limited number of files, ranging from 22 to around 30.

If I copy all the files in the same test folder (I was using ~100KB jpeg's), it works up to 22. Never 23.

If I select a mixed bag of various sizes (~200 KB - 10 MB) and file types from a large folder, it allows >22 files but the number varies. The total size of all the files doesn't affect the outcome. I tried putting a pause (PING 1.1.1.1 -n 1 -w 1000 >NUL) before the copy line, but it had no effect. Being able to copy ~20 files is enough for almost all my uploads, so it's not a big problem. The Windows error message that comes up *immediately* after hitting enter is:

Windows cannot access the specified 
device, path, or file. You may not have the ` appropriate permisiions to access the item.

The title of the message is the path to the bat file.

> You don't necessarily need to 
> use the START command to 
> mount your DropBox drive.

I was using the START command, because I wanted the mounting to complete before going to the next line, and I thought you can only use /WAIT after START.

I don't know why I was confused in the original linked article as to how SHIFT worked to enable >9 parametes here: http://www.robvanderwoude.com/parameters.php , but when 
I found this explanation in another article it became clear:

This permits each file name on the 
command line to move down one 
number to become the first replaceable 
parameter. Thus, the second file name 
will become "%1" after the SHIFT command 
is issued," [...] Then, each is deleted in turn "

http://www.chebucto.ns.ca/~ak621/DOS/BatExamp.html

Thanks again for the invaluable help.


----------



## Squashman (Apr 4, 2003)

Batch files are sequential. Which means it won't process the next command until the previous command completes. The only exception to that rule is when using the START command. If you use the START command without the WAIT it spawns another process and proceeds to the next command in your batch file. If you run your executable without the start command it will not go on to the next command until it is done mounting your Web Drive.

In Regards to your error...."Windows cannot access the specified device, path, or file. You may not have the ` appropriate permisiions to access the item. " This is a command line limitation. I just had this conversation with Rob Vander Woude a couple of months ago about this error because the Windows KB article is incorrect.. You are limited to 2047 characters that you can drag and drop onto your batch file with XP regardless of what the KB article says. This includes the path to the file name and the spaces and quotes it puts around it.

So if you drag two files onto your batch file in the folder C:\Temp, your batch file sees this:
"C:\Temp\file1.txt" "C:\Temp\File2.txt"
So that is 39 characters already. Depending on how long the path is to the files you are dragging and dropping, it is going to limit the number of files you can process at one time.


----------

