Dark Lord
Dark Lord

Reputation: 41

Drive name in batch

I need help with a batch script. I want one folder to sync with external usb device that has specific name (not drive letter; e.g. john's usb). I found formula to sync folders:

robocopy "source folder" "destination folder" /e /purge

Source folder is not problem because it's specific folder on my drive but destination folder should be external usb with specific name (e.g. John's usb). I can't do this using drive letters because sometimes I have more than 1 usb sticks connected in PC. Hope someone can help. Regards

Upvotes: 0

Views: 608

Answers (1)

Stephan
Stephan

Reputation: 56155

find the correct drive letter:

for /f "usebackq tokens=2 delims=:=" %%a in (`wmic logicaldisk where VolumeName^="John's usb" get caption /value`) do set drive=%%a:
if "%drive%"=="" (
  echo not inserted
) else (
  echo inserted as %drive%
)

Upvotes: 2

Related Questions