Solved

What is the syntax for USB drive letter?

Posted on 2008-10-25
6
364 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help on writing a script for check ndf file size 2 82
Batch: check service status 11 87
robocopy 6 60
Batch Script for opening the DOS prompt and run a command 9 105
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 …
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 …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

895 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

15 Experts available now in Live!

Get 1:1 Help Now