Results 1 to 3 of 3
  1. #1
    Lounger
    Join Date
    Dec 2009
    Location
    Chicago, IL, USA
    Posts
    46
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Batch file can't access USB drive

    I have a batch file that I use to copy files from an internal hard drive (D to an external USB drive (Q. Since my machine crashed and I've reinstalled Win 7 Professional x64, the batch file does not recognize Q: and so can't copy files to it with the XCOPY command.

    When I put the following lines in the batch file

    if not exist Q:\nul echo problem
    pause

    I get a "problem" output. If I do the same thing manually in a cmd box I don't. I can copy files fine from a cmd box but not from a batch file. Anyone know what's going on here? This was not a problem before the crash. Thanks!

  2. #2
    Lounger
    Join Date
    Dec 2009
    Location
    Chicago, IL, USA
    Posts
    46
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Never mind, it was apparently a sharing issue.

  3. #3
    Super Moderator BATcher's Avatar
    Join Date
    Feb 2008
    Location
    A cultural area in SW England
    Posts
    2,823
    Thanks
    19
    Thanked 108 Times in 102 Posts
    Since the assignment of drive letters to USB drives can be a bit iffy, it's worth incorporating something in your BATch file which determines which drive letter a particular USB drive is currently addressed by.

    For this, you need to give your USB drive a proper name such as My983GBUSB, (or perhaps to know its Volume Serial Number, but that's quite a bit messier), and look for it in DIR, where the useful output line is
    Volume in drive F is My983GBUSB (F:)

    for %%a in (E F G H I J K L M N O P Q R S T U V W X Y Z) do (
    dir %%a: 2>nul | find /i "My983GBUSB" && set drvlet=%%a
    )
    echo Drive letter for My983GBUSB = %drvlet%


    Adjust to suit!
    Last edited by BATcher; 2013-07-05 at 01:43.
    BATcher

    Dear Diary, today the Hundred Years War started ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •