?
Solved

What is the syntax for USB drive letter?

Posted on 2008-10-25
6
Medium Priority
?
370 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 1000 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Suggested Courses

770 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