Jump to content
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble
Strawberry Orange Banana Lime Leaf Slate Sky Blueberry Grape Watermelon Chocolate Marble

MSFN is made available via donations, subscriptions and advertising revenue. The use of ad-blocking software hurts the site. Please disable ad-blocking software or set an exception for MSFN. Alternatively, register and become a site sponsor/subscriber and ads will be disabled automatically. 


Sign in to follow this  
wanako1

How to find drive letter of a specific file in batch?

Recommended Posts

Hello Everyone....

I have been out in this area for a while (anyways I know almost nothing about it)

I need some Help (hope anyone can give me a hand!)

I want to make a USB with Autorun (2 Partitions)

- fist partition as UDF (where I need the Autorun.ini) and a start.cmd or start.bat (or something better that you can help me with) 

    Will work as a CD Drive

- second partition as NTFS ot FAT32 where the DPI.exe will be (this exe will call DPI.exe [Driver Pack Installer]), my problem is:

How to Call DPI.exe from cmd or bat (unknowing the right Unit Letter where my file is located [See Picture below) in this case is on Unit L (what about if is used in another PC)

I hope you can understand what i mean and help me with this script/command not sure how to call it

 

USB.thumb.png.7adbf62c8f8dfee4222d7c99ce471ef6.png

 

 

Thanks!!!

 

Edited by Tripredacus
title

Share this post


Link to post
Share on other sites

It depends on the environment.

The easiest would be to use a "tag" file of sort,

Then you simply find the volume which contains this "tag" file, let's say it is a 0 byte file named thisisit.tag.

The problem might be that in order to find the volume you need to list or check  the contents of all volumes, and depending on the speciific OS there may be issues with devices that have been assigned a drive letter but that do not really "exist", a classic example is (again it depends on OS) those "media" readers (internal but USB connected) that sport a couple USB ports, a SD and a CF reader, etc. and with volumes with thousands of files there could be time issues.

See starting from here for a few posts:

 

 

Here is another approach (due to some issues in the nth board update the formatting of CODE contents has been ruined, so you will need some patience, after having done copy and paste to rebuild the actual batches proposed):

In your specific case, I would rather check the Registry and get the drive letter associated to the Disk Signature and Offset of your USB stick, however (assuming that you are not going to change either).

But this depends again on the environment and the device, you cannot use this method if the device is removable (or you can use it only to exclude non-removable devices).

jaclaz

 

Edited by jaclaz

Share this post


Link to post
Share on other sites

If you can use VBS here is a VBS script that checks all local active drives searching for

a file called Test.txt. 

'-> Objects For Run Time
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
'-> Varibles For Run Time 
Dim Chk, Drv, Fil, Tmp
'-> File Name To Search For
Fil = "\Test.txt"
'-> Check File Set To False If Found It Becomes True
Chk = False
'-> Loop For All The Drives
   For Each Drv In Fso.Drives
'-> If Drive is Active
    If Drv.IsReady = True Then
'-> Check For The File On A Active Drive
     If Fso.FileExists(Drv & Fil) Then
'-> If Check File Found Do Some Action   
       WScript.Echo Drv & Fil
       Chk = True 
     Else
'-> Colllect The Drives That Are Missing The Check File
      Tmp = Tmp & "Missing : " & Drv & Fil & vbCrLf
     End If 
    End If 
   Next 
'-> If The Check File Is Missing
   If Chk = False Then
    WScript.Echo Tmp    
   End If 

 

Share this post


Link to post
Share on other sites

In this example, it looks like Start.bat is on L: and DPI.exe will be on M:.
Start.bat knows the path for DPI.exe, but not its drive letter.
Check for Z:\path\DPI.exe and work backwards.
Or Start.bat can determine its own drive letter (using %0) and work forward.
Each drive could also be checked for a matching label (or other identifier) first.

If exist z:\path\dpi.exe z:\path\dpi.exe | exit
If exist y:\path\dpi.exe y:\path\dpi.exe | exit
...
If exist c:\path\dpi.exe c:\path\dpi.exe | exit
echo Oops!
pause

(A For %%d in (Z Y ... C) do loop could also be used.)

Edited by jumper

Share this post


Link to post
Share on other sites

Thanks for providing a link this time (instead of just a blank embed). Good read. :yes:

I have one of those combo USB readers on my XP box that pre-assigns drive letters and if exist and if not exist both work just fine on empty slots. However, I was able to get a feel for the frustration of dealing with empty media errors on problem devices by testing empty drive a:.

If the OP returns and gets everything working except dealing with problem devices, we can write a plugin to solve it.

Share this post


Link to post
Share on other sites
18 minutes ago, jumper said:

Thanks for providing a link this time (instead of just a blank embed). Good read. :yes:
 

I don't get it. :unsure:

It is not a "blank embed", it is the SAME link (and it is clickable), that the stupid board software insists on automagically transform into the stupid preview unless you are fast enough to tell it explicitly to "display as link instead", here are two times the same link:

 

The above has been magically transformed, the below one is the same copy/paste BUT clicking on "display as link instead":

https://msfn.org/board/topic/137714-install-xp-from-a-ram-loaded-iso-image/?page=8&tab=comments#comment-895119

 

It is entirely possible that some of the XP updates post 2009/2010 fixed the issue, good to know that it works on your machine/OS :), as said it depends on OS (and possibly also on the specific devices, I remember the behaviour to be faulty also with USB ZIP disks besides my multimedia card reader).

 

jaclaz

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×