Link to home
Start Free TrialLog in
Avatar of parcou
parcou

asked on

How copy files to a removable drive by DRIVE NAME, not letter in DOS

I need to write a .bat file for my sales reps in the field to copy specific files to a drive by the NAME of the drive and not by drive letter to a removable source (Jump drive, SD, CF, etc.). They are on Win2000 and do have network drives when on the LAN. This is a problem for me because all my reps will not have the same removable drive letter.

How can write the code in DOS to take files from the local (c:) drive and copy them to a removable drive by its DRIVE name and not by drive letter? I am not computer dumb but I would appreciate it if you would be detailed in the instructions.

eg.
SD card, drive name "REP" - with a folder in the root directory called "backup"

xcopy "c:\documents and setting\%username%\my documents" (here... what script can I use to copy files to the removable drive by Drive Name)

it may be more detailed than this but I wanted to give you an idea

Thx
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

You can't copy by name in a batch file.  However, you can have the batch file look for a specific file or folder and in locating it, assign a drive letter to use.

For example:

For %%a 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 (
    If exist %%a:\backup (
        set useLetter=%%a:
        goto EndLetterChk
    )
)
:EndLetterChk

xcopy "%userprofile%\my documents\filespec.ext" %useLetter%
While it is not easy if you really want to we could scan down all drive letters and identify which one is REP by it's label - easiest way is to strip it out using FOR and a DIR command.  I'm not on a PC right now but will look for you in about 2hrs but basically it would look at a list of drive letters then check the label and when found do your xcopy to it.

It is easier to identify a flag file on the drive as leew has already suggested though.

Steve
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of parcou
parcou

ASKER

Thx dragon-it...

The only part I am a bit confused on is:

REM use Dir to get drive label.  Sets drive variable

Do I need to execute a command here?

-parcou

No that is just a comment about the next line, you can leave it there or delete it.  It was tested and working for me but may need tweaking for different machines... try it and report back any issues.

Steve
Avatar of parcou

ASKER

Buddy you are right and I realized that afterwards, brain dead....the code works great I just had a little issue where it was not copying to the drive. There was a % sign missing at the DRIVE....no complaints from me...you gave me 99% of what I needed I would be a fool to complain on something I can visibly find...

It works great!!!

Thank you!!!!

-parcou
Sorry about that last bit, was only a remmed out comment of what you may want to add anyway!

Glad it worked for you.

Steve