How can I tell if a drive is a SUBSTitute?

#1
I have a simple alias:

alias freee=for %%A in (%%_ready) do free %%A

Works nicely, but if I have a substituted drive:

subst D: C:\PERSONAL

The output of the said command will display the free size of the C: drive twice:

Volume in drive C is PRINCIPAL Serial number is 2c4e:febc
36.702.134.272 bytes total disk space
36.085.678.080 bytes used
616.456.192 bytes free
98,3 % in use

Volume in drive D is PRINCIPAL Serial number is 2c4e:febc
36.702.134.272 bytes total disk space
36.085.678.080 bytes used
616.456.192 bytes free
98,3 % in use

Volume in drive F is FUENTES Serial number is 7446:3762
3.305.562.112 bytes total disk space
1.660.338.176 bytes used
1.645.223.936 bytes free
50,2 % in use


I've looked around, but I can't find a simple way to tell if a particular drive has been substituted. Ideally, my alias would be this:

alias freee=for %%A in (%%_ready) do if %%@substituted[%%A] == 1 free %%A

Yes, I know @subst[] is already taken.
 
#2
This works for me:

D:\>function substituted=%%@if[%%@truename[%%1\]==%%1\,0,1]

D:\>echo %@substituted[c:]
0

D:\>echo %@substituted[d:]
1

D:\>subst
D:\: => C:\RAM

On Mon, Jan 24, 2011 at 15:02, mfarah <> wrote:


> I have a simple alias:
>
> alias freee=for %%A in (%%_ready) do free %%A
>
> Works nicely, but if I have a substituted drive:
>
> subst D: C:\PERSONAL
>
> The output of the said command will display the free size of the C: drive
> twice:
>
> Volume in drive C is PRINCIPAL Serial number is 2c4e:febc
> 36.702.134.272 bytes total disk space
> 36.085.678.080 bytes used
> 616.456.192 bytes free
> 98,3 % in use
>
> Volume in drive D is PRINCIPAL Serial number is 2c4e:febc
> 36.702.134.272 bytes total disk space
> 36.085.678.080 bytes used
> 616.456.192 bytes free
> 98,3 % in use
>
> Volume in drive F is FUENTES Serial number is 7446:3762
> 3.305.562.112 bytes total disk space
> 1.660.338.176 bytes used
> 1.645.223.936 bytes free
> 50,2 % in use
>
>
> I've looked around, but I can't find a simple way to tell if a particular
> drive has been substituted. Ideally, my alias would be this:
>
> alias freee=for %%A in (%%_ready) do if %%@substituted[%%A] == 1 free %%A
>
> Yes, I know @subst[] is already taken.
>
>
>
>
>


--
Jim Cook
2010 Sundays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Monday.
 

samintz

Scott Mintz
May 20, 2008
1,270
11
Solon, OH, USA
#3
This is the code I use:

unset /q sl & do d in /p subst (set
sl=%[sl]%@left[1,%d])
function IsSubst=%@if[%@index[%sl,%@left[1,%1]]
== -1,0,1]

echo %@IsSubst[c:]
echo %@IsSubst[w:]

-Scott




mfarah <> wrote on 01/24/2011
06:02:27 PM:


> mfarah <>
> 01/24/2011 06:02 PM
>
> Please respond to
>
>
> To
>
> [email protected]
>
> cc
>
> Subject
>
> [Support-t-2556] How can I tell if a drive is a SUBSTitute?
>
> I have a simple alias:
>
> alias freee=for %%A in (%%_ready) do free %%A
>
> Works nicely, but if I have a substituted drive:
>
> subst D: C:\PERSONAL
>
> The output of the said command will display the free size of the C:

> drive twice:
>
> Volume in drive C is PRINCIPAL Serial number
is 2c4e:febc

> 36.702.134.272 bytes total disk space
> 36.085.678.080 bytes used
> 616.456.192 bytes free
> 98,3 % in use
>
> Volume in drive D is PRINCIPAL Serial
number is 2c4e:febc

> 36.702.134.272 bytes total disk space
> 36.085.678.080 bytes used
> 616.456.192 bytes free
> 98,3 % in use
>
> Volume in drive F is FUENTES Serial
number is 7446:3762

> 3.305.562.112 bytes total disk space
> 1.660.338.176 bytes used
> 1.645.223.936 bytes free
> 50,2 % in use
>
>
> I've looked around, but I can't find a simple way to tell if a
> particular drive has been substituted. Ideally, my alias would be
this:

>
> alias freee=for %%A in (%%_ready) do if %%@substituted[%%A] == 1 free
%%A

>
> Yes, I know @subst[] is already taken.
>
>
>
>
 
#4
---- Original Message ----
From: mfarah
To: [email protected]
Sent: Monday, 2011. January 24. 18:02
Subject: [Support-t-2556] How can I tell if a drive is a SUBSTitute?

| I have a simple alias:
|
| alias freee=for %%A in (%%_ready) do free %%A
|
| Works nicely, but if I have a substituted drive:
|
| subst D: C:\PERSONAL
|
| The output of the said command will display the free size of the C:
| drive twice:
|
| Volume in drive C is PRINCIPAL Serial number is 2c4e:febc
| 36.702.134.272 bytes total disk space
| 36.085.678.080 bytes used
| 616.456.192 bytes free
| 98,3 % in use
|
| Volume in drive D is PRINCIPAL Serial number is 2c4e:febc
| 36.702.134.272 bytes total disk space
| 36.085.678.080 bytes used
| 616.456.192 bytes free
| 98,3 % in use
|
| Volume in drive F is FUENTES Serial number is 7446:3762
| 3.305.562.112 bytes total disk space
| 1.660.338.176 bytes used
| 1.645.223.936 bytes free
| 50,2 % in use
|
|
| I've looked around, but I can't find a simple way to tell if a
| particular drive has been substituted. Ideally, my alias would be
| this:
|
| alias freee=for %%A in (%%_ready) do if %%@substituted[%%A] == 1 free
| %%A
|
| Yes, I know @subst[] is already taken.

I would use %_hdrives instead of %_ready to exclude network and removable drives (unless you want to report on CD/DVD and plug-in devices, e.g. memory sticks).

The function below is an untested implementation of your @substituted[] function, based on what I use for like purpose:

function substituted=`%@if[%1 EQ %@left[2,%@truename[%1]],0,1]`

It uses the usual values 1 if %1 is a drive created by SUBST (or possibly by using Windows Explorer's drive mapping locally) and 0 if it is a real drive. Note that these values in your alias would report ONLY substituted drives; you should test for 0 or for "not 1" if I understood your intent correctly.

Note how the use of backticks in the definition eliminates the need for special handling of percent signs %, making it much more readable.
--
HTH, Steve
 
#5
I would use %_hdrives instead of %_ready to exclude network and removable drives (unless you want to report on CD/DVD and plug-in devices, e.g. memory sticks).
Yup, I'm using %_ready intentionally. While I almost never use network drives, I very often mount SD cards whose contents I have to move to the hard drive (mostly pictures taken with a digital camera). The freee alias allows me to quickly know how much I'll be moving in.


The function below is an untested implementation of your @substituted[] function, based on what I use for like purpose:

function substituted=`%@if[%1 EQ %@left[2,%@truename[%1]],0,1]`

It uses the usual values 1 if %1 is a drive created by SUBST (or possibly by using Windows Explorer's drive mapping locally) and 0 if it is a real drive. Note that these values in your alias would report ONLY substituted drives; you should test for 0 or for "not 1" if I understood your intent correctly.
Yes, indeed. I made a typo in my original post.

Note how the use of backticks in the definition eliminates the need for special handling of percent signs %, making it much more readable.
In the end, since I have all my aliases in a text file that gets read at startup, I didn't need it.


Anyway, since I don't need to test for substituted drives somewhere else, I decided to integrate the proposed function into the alias itself. This is the final result:

freee=for %A in (%_ready) do if "%A" eq "%@left[2,%@truename[%A]]" (free %A)

Works as intended. :-)

Thanks to all.