Solved

What is the syntax for USB drive letter?

Posted on 2008-10-25
6
363 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 95

Expert Comment

by:Lee W, MVP
Comment Utility
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
Comment Utility
You take it correctly!

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

Author Comment

by:pauldownham
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now