Copy from unknown drive letter batch file

Microsoft Windows xp professional w/ sp2
December 20, 2009 at 08:14:28
Specs: Windows XP, P4 3Ghz 1G ram
I need to copy from a path on a usb. the batch file is in the main directory. I copy to the same location every time.
I can do %system%, but not the usb drive. Changes every time too.

The Computer Dr
Chris Robertson
www.puterdr.com
chris@puterdr.com


See More: Copy from unknown drive letter batch file

Report •


#1
December 20, 2009 at 11:24:16
The problem is that when doing checks on drives, sometimes very weird stuff happens when checking a given driveletter.

One approach would be :
Create a script which writes a file in a given drive, example:

----- checkdrive.cmd -------------------
@echo off

set drive=%1

echo test > %drive%\this_is_a_test.txt
-------------------------------------------------

Then, write a script to do this:

- script.cmd -------------------------------
@echo off

set drive=%1
set valid=no

del %drive%\this_is_a_test.txt
start checkdrive.cmd %drive%
sleep 10
if exist %drive%\this_is_a_test.txt set valid=yes
echo Drive %drive% is valid : %valid%
-------------------------------------------------

Note:
- "sleep" is not default MS, but you NEED to have a wait of some sort there, otherwise it'll fail
- I'm not including error handling in the above, it's about the idea
- Drive can be both "D:" and "D", keep that in mind


Report •

#2
December 21, 2009 at 13:22:45
might add a loop to check for all driveletters:
(adjust for the actual "minimum drive letter" which needs to
bypass the cd drive and any other harddrives)
set minim=d e f
for %%a in (!minim! g h i j k l m n o p q r s t u v w x y z) do (
checkdrive %%a)

but i think you would want to cut down or eliminate the
"sleep". even at 1 second, still takes 23 seconds to run all the letters (over c)


Report •

#3
December 21, 2009 at 20:09:59
This is probably a bit over the top.....

http://pastebin.com/m71e78d6c


Batch Variable how to


Report •

Related Solutions

#4
December 21, 2009 at 20:28:59
not at all over top imo, i liked it!
(also dumped pastebin into my fav's for later exam)

Report •

#5
December 21, 2009 at 20:37:03
Yeah, pastbin's good for those 100+ line scripts that just ugly up the forum. Not needing an account is a bonus.


Batch Variable how to


Report •

#6
December 23, 2009 at 05:15:00
Thanks for your replies!

The Computer Dr
Chris Robertson


Report •

#7
December 23, 2009 at 07:54:09
@crobertson: disregard this post, I can't help myself.

War of section moderates *ding*


Batch Variable how to


Report •


Ask Question