1.

Solve : Batch file help?

Answer»

Depending on which of two physical external hard drives I connect to the same USB port on my computer that drive shows up on My Computer as either Drive F: or Drive H:.

I have composed a BATCH file that copies certain FILES to the "F: drive". However if the "H: drive" happens to be CONNECTED at the TIME, the copy process fails because the batch file is looking for the F: drive. But... I don't really care which physical drive (F: or H:) is being copied to.

I need to modify the batch file to go ahead and copy to the H drive if that one happens to be installed instead of the F drive. In pseudo code that might look like:

Is the drive connected to the USB port the F: drive ?
Go ahead and copy the specified files
Is the drive connected to the USB port the H: drive ?
Go ahead and copy the specified files


In other words, copy the specified files to the drive connected to the USB port no matter what drive letter the OS sees.

Using XP home with SP3


Thanks for your assistance.I always thought removable drive letters were assigned sequentially, so I'm not understanding why you get two different assignments. Be that as it may, you can check which drive is mounted and proceed from there:

Code: [Select]@echo off
setlocal

for /f "tokens=3" %%i in ('echo list volume ^| diskpart ^| findstr /c:" F " /c:" H "') do (
xcopy <put xcopy parameters here> && goto :eof
)

Replace <put xcopy parameters here> with actual arguments. The drive letter is in the %%i variable. Leave the && goto :eof as written.

Example: xcopy c:\windows\inf %%i:\backup /s /e && goto :eof

Good luck.

PS. This snippet is specific to your request. VBScript or Powershell might be a better choice to create a generic script.



Discussion

No Comment Found