Solved

What is the syntax for USB drive letter?

Posted on 2008-10-25
6
369 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 96

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
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 
LVL 96

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

717 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