Found logical drive letter

  • Thread starter Thread starter Dada
  • Start date Start date
D

Dada

Hi,
i must use the logical letter where exist a specificated directory. It's
possible?

Es for run F:\app1 i must know the drive letter first., therefore:
c:\cd 'Drive letter'
app1

Thanks
 
If you are using a .CMD file, you can have a section that extracts the drive
letter of an argument and returns it in a variable. Here's an example:

@echo off
rem Batch file that echos the drive letter on all it's parameters
rem Yes, it's the hard way

:top
if "%1" == "" goto :eof

call :GetDriveLetter %1

echo Drive letter of %1 is %result%

shift
goto :top

:GetDriveLetter

set result=%~d1
goto :eof
 
I don't know if I'm exactly clear on what you're asking. From what I gather
you want to "Use the logical letter where exist a specified (spelling
corrected) directory".

Perhaps the SUBST command?

C:\>subst /?
Associates a path with a drive letter.

SUBST [drive1: [drive2:]path]

<snip>

Example:

C:\>SUBST Z: C:\mydirectory

Just my 2.0134 cents worth (tax included)
Scot Wiedenfeld
 
If you don't know what the drive letter is, then your script isn't going to
be able to figure it out by using magic. Maybe the drive letter is stored
in the registry or in a shortcut?

To change to a new drive, just enter the drive letter and the colon, like
this:

C:\>f:

F:\>


Or, you can use "cd /d" like this:

C:\>cd /d F:\MyDIR

F:\MyDir>start MyAPP

F:\MyDir>exit
 
Dada wrote in
Excuse me for my english and for my unclear mex.
I must run a application (for ex. named MyAPP) a server using a
.BAT file, but i don't know the logical letter (C: or D: or ecc..)
where this application is saved; i know the directory name only
(for ex named MyDIR). Ex, if must run MyAPP in MyDIR directory but
i don't know the disk location, how make to run it?

Ex of promt cmd:

C:\ <logical letter>: (i digit the letter driver where
application is saved (??? I don't know..))
<logical letter> cd\ (i go to directory)
<logical letter> cd MyDIR
<logical letter> start MyAPP (I run application and exit)
<logical letter> exit

How make for found <logical letter> where MyDIR is saved?

If I understand correctly then why not just try them all?
IF EXIST C:\mydir\myapp.exe START C:\mydir\myapp.exe
IF EXIST D:\mydir\myapp.exe START D:\mydir\myapp.exe
IF EXIST E:\mydir\myapp.exe START E:\mydir\myapp.exe
...
IF EXIST Z:\mydir\myapp.exe START Z:\mydir\myapp.exe

Or do the same using a FOR statement.

Or other variations of testing all possible
drives/directories/executable file.
 
Back
Top