English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I want to make a batch file copy files from my external hardrive onto any computer but I have to have the destination of the files to be coppied in my command line.The problem is I want it to work on anyones computer and my external hardrive can show up as any drive letter making a destination in a command line invalid if my hardrive shows up as a different letter which is a good chance.Any ideas? thanks

2007-04-20 19:43:00 · 3 answers · asked by Anonymous in Computers & Internet Other - Computers

3 answers

No problem. You can do this with a simple commandline in your batch file that looks for a unique file on your external harddrive. When it finds the file, it detects the drive letter, and assigns it to a variable which you can use in the rest of your batch file as the destination drive letter.

Something like this,
1) Create a flag file on the root of your external hard drive. Let's call that flag.txt. Or, you could substitute with another unique file that's on the drive.

2) Run the following command at the top of your batch file to find which drive letter your external hard drive was assigned to. This is all on one line. Answers wraps stuff to more than one line.

for %i in (d e f g h i j k l m n o p q r s t u v w x y z) do dir %i:\flag.txt && set mydriveletter=%i

This will run through the letters d -z and run,
dir d:\flag.txt
dir e:\flag.txt
..etc.

If it doesn't find the file, it will move on to the next letter. When it does find the file, then the "&&" says, when the preceding command succeeds, run the following command.

So, if your drive gets assigned to F:,
then "dir f:\flag.txt" will succeed, and the batch will create the environment variable "mydriveletter" and set it to F

The rest of your batchfile can use this environment variable as an alias to the destination, like

copy %mydriveletter%:\source\*.* c:\destination

2007-04-22 06:42:19 · answer #1 · answered by Kevin 7 · 2 0

This does'nt work

may be u can write a program in VB or other software
that is interactive
i.e
asks the use whether to copy and from which drive to location

You can even make the program run as the start up program for mass storage usb

2007-04-20 19:50:04 · answer #2 · answered by Sairam 2 · 0 1

first connect your external hard drive properly. then u can copy the file in it.

2016-05-20 01:42:36 · answer #3 · answered by lindsay 3 · 0 0

fedest.com, questions and answers