Solved

What is the syntax for USB drive letter?

Posted on 2008-10-25
6
366 Views
Last Modified: 2012-05-05
I have a USB drive with diagnostic software on that runs from a batch file, and the software generates a report that is saved back to the external drive.

The problem is that I have to stipulate the destination path for the report within the batch file, but the USB drive takes on different drive letters when connected to different computers.

So what I need is the syntax to say "this drive", or maybe a line of code to put in the batch file that can look it up?

Thanks
0
Comment
Question by:pauldownham
  • 3
  • 2
6 Comments
 
LVL 17

Expert Comment

by:JohnGerhardt
ID: 22802334
I might stand correct but a batch file will not be able to pull the path that it was launched from..
The best way to do this would be to use a vbscript to pull the path then launch the batch file passing the drive letter to the batch file...
0
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 250 total points
ID: 22802336
Hello pauldownham,

have it look for a specific, unique file... in my backup batch file, I look for a file, then set a variable to the drive letter it's found on.  See the sample:

:CheckForDrive
For %%a in (B,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.txt (
            Set BackupDrive=%%a:
            Goto EndDriveChk
      )
)
:EndDriveChk



Regards,

leew
0
 

Author Comment

by:pauldownham
ID: 22802429
John,  thanks for being the first to respond, but I think the answer from Lee is exactly what I'm looking for.

Lee, this looks good, but I can't try it out until tomorrow (I left the drive at work!). Also, can you please just clarify the exact syntax for using the discovered drive letter ... at the moment the batch file reads:

software.exe /s /e:report.txt  

so I add a unique file (myfile.txt), and change the batch file to:

:CheckForDrive
For %%a in (B,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:\myfile.txt (
            Set BackupDrive=%%a:
            Goto EndDriveChk
      )
)
:EndDriveChk
software.exe /s /BackupDrive:report.txt

Thanks
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 22803765
I take it you're not familiar with environment variables...

Your line would read

software.exe /s /%BackupDrive%:report.txt
0
 

Author Comment

by:pauldownham
ID: 22803799
You take it correctly!

Many thanks, I'll test this tomorrow ...  
0
 

Author Comment

by:pauldownham
ID: 22806709
Lee,

I've tested this now, and it just needed a little tweek ... the whole software switch string needed to be substituted like this:

:CheckForDrive
For %%a in (B,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:\myfile.txt (
            Set SoftwareSwitches=/s /%%a:\report.txt
            Goto EndDriveChk
      )
)
:EndDriveChk
software.exe %SoftwareSwitches%

Possibly a quirk of software.exe?

Anyway, all working now, so many thanks and points awarded.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question