Batch file to show Network drives

  • Thread starter Thread starter joshboski
  • Start date Start date
J

joshboski

I am currently trying to write a batch file that will delete a list of
files from all of my network drives. The problem I am having is
getting the network drives. I am on a rather large network, and I
would like this to run on several different computers that may be
connected to different drives.
 
See "net use" and "If exist" in Windows Help and support. Also there is
a cmd prompt group that has some pretty sharp folks(cross posting this)

news://msnews.microsoft.com/microsoft.public.win2000.cmdprompt.admin

joshboski wrote:

> I am currently trying to write a batch file that will delete a list of
> files from all of my network drives. The problem I am having is
> getting the network drives. I am on a rather large network, and I
> would like this to run on several different computers that may be
> connected to different drives.
 
On Jun 3, 9:21 am, Bob I <bire...@yahoo.com> wrote:
> See "net use" and "If exist" in Windows Help and support. Also there is
> a cmd prompt group that has some pretty sharp folks(cross posting this)
>
> news://msnews.microsoft.com/microsoft.public.win2000.cmdprompt.admin
>
> joshboski wrote:
> > I am currently trying to write a batch file that will delete a list of
> > files from all of my network drives. The problem I am having is
> > getting the network drives. I am on a rather large network, and I
> > would like this to run on several different computers that may be
> > connected to different drives.


My apologies, that I did not include this also...I need the list of
local hard drives as well
 
"joshboski" <josh.burkholder@gmail.com> wrote in message
news:4e9ec7fc-5000-4ab5-bbe8-115ebce19dde@j22g2000hsf.googlegroups.com...
> On Jun 3, 9:21 am, Bob I <bire...@yahoo.com> wrote:
>> See "net use" and "If exist" in Windows Help and support. Also there is
>> a cmd prompt group that has some pretty sharp folks(cross posting this)
>>
>> news://msnews.microsoft.com/microsoft.public.win2000.cmdprompt.admin
>>
>> joshboski wrote:
>> > I am currently trying to write a batch file that will delete a list of
>> > files from all of my network drives. The problem I am having is
>> > getting the network drives. I am on a rather large network, and I
>> > would like this to run on several different computers that may be
>> > connected to different drives.

>
> My apologies, that I did not include this also...I need the list of
> local hard drives as well


As Bob recommended: net use (for networked drives), and
mountvol | find ":\" for local drives.
 
"joshboski" <josh.burkholder@gmail.com> wrote in message
news:4e9ec7fc-5000-4ab5-bbe8-115ebce19dde@j22g2000hsf.googlegroups.com...
> On Jun 3, 9:21 am, Bob I <bire...@yahoo.com> wrote:
>> See "net use" and "If exist" in Windows Help and support. Also there is
>> a cmd prompt group that has some pretty sharp folks(cross posting this)
>>
>> news://msnews.microsoft.com/microsoft.public.win2000.cmdprompt.admin
>>
>> joshboski wrote:
>> > I am currently trying to write a batch file that will delete a list of
>> > files from all of my network drives. The problem I am having is
>> > getting the network drives. I am on a rather large network, and I
>> > would like this to run on several different computers that may be
>> > connected to different drives.

>
> My apologies, that I did not include this also...I need the list of
> local hard drives as well


If you want something a little snazzier then you can use this script
file and massage it to give you the information you want. You need
to invoke it like so in your batch file: cscript //nologo c:\diskparms.vbs

Const Removable = 1
Const Fixed = 2
Const Network = 3
Const CDROM = 4
Const RAMDisk = 5

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set drives = oFSO.Drives

NewLine=Chr(10)
Line = ""

For Each drive In drives
Line = Line & "Drive " & drive.Path
Line = Line & " " & ShowDriveType(Drive)
If drive.IsReady Then Line = Line & ", ready" Else Line = Line & ", not
ready"

If drive.IsReady Then
If drive.DriveType=Network Then
Line = Line & ", Label=" & drive.ShareName
Else
Line = Line & ", Label=" & drive.VolumeName
End If

Line = Line & ", FS=" & drive.FileSystem
Line = Line & ", Total=" & Int(drive.TotalSize/1000000)
Line = Line & ", Free=" & Int(drive.FreeSpace/1000000)
Line = Line & ", Available=" & Int(drive.AvailableSpace/1000000)
Line = Line & ", Serial=" & Hex(drive.SerialNumber)
End If

Line = Line & NewLine
Next
wscript.echo Line

Function ShowDriveType(Drive)
Select Case drive.DriveType
Case Removable
T = "Removable"
Case Fixed
T = "Fixed"
Case Network
T = "Network"
Case CDROM
T = "CD-ROM"
Case RAMDisk
T = "RAM Disk"
Case Else
T = "Unknown"
End Select
ShowDriveType = T
End Function
 
Not as backwards compatible as some solutions offered here but,
nonetheless, worth a mention -

C:\>fsutil fsinfo drives

Drives: C:\ D:\ E:\ Z:\

.... iterating through that list and using -

C:\>fsutil fsinfo drivetype <insert drive letter here>

.... will return greater detail regarding the type of drive assignment.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l


"Bob I" <birelan@yahoo.com> wrote in message
news:er75LzXxIHA.5472@TK2MSFTNGP06.phx.gbl...
> See "net use" and "If exist" in Windows Help and support. Also there
> is a cmd prompt group that has some pretty sharp folks(cross posting
> this)
>
> news://msnews.microsoft.com/microsoft.public.win2000.cmdprompt.admin
>
> joshboski wrote:
>
>> I am currently trying to write a batch file that will delete a list
>> of
>> files from all of my network drives. The problem I am having is
>> getting the network drives. I am on a rather large network, and I
>> would like this to run on several different computers that may be
>> connected to different drives.

>
 
"Dean Wells (MVP)" <dwells@maskmsetechnology.com> wrote in message
news:%23EsU3iYxIHA.5520@TK2MSFTNGP06.phx.gbl...
> Not as backwards compatible as some solutions offered here but,
> nonetheless, worth a mention -
>
> C:\>fsutil fsinfo drives
>
> Drives: C:\ D:\ E:\ Z:\
>
> ... iterating through that list and using -
>
> C:\>fsutil fsinfo drivetype <insert drive letter here>
>
> ... will return greater detail regarding the type of drive assignment.
>
> --
> Dean Wells [MVP / Directory Services]
> MSEtechnology


For reasons which I am unable to explain, Microsoft turned the
output of the command "fsutil fsinfo drives" into a set of $00-delimited
strings. The result is that I am unable to extract the individual
drive letters out of the string "Drives: C:\ D:\ E:\ F:\ Q:\ R:\",
using a batch file. Do you know of a way to do this?
 
joshboski <josh.burkholder@gmail.com> wrote:
> My apologies, that I did not include this also...I need the list of
> local hard drives as well


53} How can I quietly test if a disk device is ready or not?
http://www.netikka.net/tsneti/info/tscmd053.htm

54} How can I get the type of a disk device?
http://www.netikka.net/tsneti/info/tscmd054.htm

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance University of Vaasa
mailto:ts@uwasa.fi <http://www.uwasa.fi/~ts/> FI-65101, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.htm
 
Nod, I encountered the same limitation ... irritating isn't it.

Take a look at the 'bootSwitch.cmd' script here -

ftp://falcon.msetechnology.com/scripts/bootSwitch.cmd.txt

.... it contains a means of resolving this behavior by exploiting an
all-too-often useful unicode oddity. Other ways were and probably still
are available though didn't give it much thought after I came it that
one.

As I'm sure you know, part of the enjoyment of solving these kind of
annoyances is the creativity involved in making such a limited
environment play nicely ... this is one of my favs. to date.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l


"Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
news:evRJvyYxIHA.548@TK2MSFTNGP06.phx.gbl...
>
> "Dean Wells (MVP)" <dwells@maskmsetechnology.com> wrote in message
> news:%23EsU3iYxIHA.5520@TK2MSFTNGP06.phx.gbl...
>> Not as backwards compatible as some solutions offered here but,
>> nonetheless, worth a mention -
>>
>> C:\>fsutil fsinfo drives
>>
>> Drives: C:\ D:\ E:\ Z:\
>>
>> ... iterating through that list and using -
>>
>> C:\>fsutil fsinfo drivetype <insert drive letter here>
>>
>> ... will return greater detail regarding the type of drive
>> assignment.
>>
>> --
>> Dean Wells [MVP / Directory Services]
>> MSEtechnology

>
> For reasons which I am unable to explain, Microsoft turned the
> output of the command "fsutil fsinfo drives" into a set of
> $00-delimited
> strings. The result is that I am unable to extract the individual
> drive letters out of the string "Drives: C:\ D:\ E:\ F:\ Q:\ R:\",
> using a batch file. Do you know of a way to do this?
>
>
 
"Dean Wells (MVP)" <dwells@maskmsetechnology.com> wrote in message
news:uzbtFFZxIHA.5652@TK2MSFTNGP06.phx.gbl...
> Nod, I encountered the same limitation ... irritating isn't it.
>
> Take a look at the 'bootSwitch.cmd' script here -
>
> ftp://falcon.msetechnology.com/scripts/bootSwitch.cmd.txt
>
> ... it contains a means of resolving this behavior by exploiting an
> all-too-often useful unicode oddity. Other ways were and probably still
> are available though didn't give it much thought after I came it that
> one.
>
> As I'm sure you know, part of the enjoyment of solving these kind of
> annoyances is the creativity involved in making such a limited environment
> play nicely ... this is one of my favs. to date.
>
> --
> Dean Wells [MVP / Directory Services]


Nicely done and highly imaginative but not my favourite.
I'm a great user of batch files but I wonder how long it
took you to get these lines just right and how maintainable
they are . . .
fsutil fsinfo drives >"%TEMP%\%~n0.$$$"
for /f "tokens=1 delims=\ skip=10" %%d in
('cmd /u /c type "%TEMP%\%~n0.$$$" ^| find /v ""') do echo %%d
 
Dean Wells (MVP) wrote:
> Nod, I encountered the same limitation ... irritating isn't it.
>
> Take a look at the 'bootSwitch.cmd' script here -
>
> ftp://falcon.msetechnology.com/scripts/bootSwitch.cmd.txt
>
> ... it contains a means of resolving this behavior by exploiting an
> all-too-often useful unicode oddity. Other ways were and probably still
> are available though didn't give it much thought after I came it that
> one.
>
> As I'm sure you know, part of the enjoyment of solving these kind of
> annoyances is the creativity involved in making such a limited
> environment play nicely ... this is one of my favs. to date.
>



Ritchie in 2003 (in alt.msdos.batch.nt) gave:


for /f "tokens=1,2" %%a in ('fsutil fsinfo drives^|more') do (
for /f "tokens=1" %%c in ('echo/%%b %%a') do fsutil fsinfo
drivetype %%c
)

terribly long google groups ref:

http://groups.google.com/group/alt....til+fsinfo+drives+batch&#doc_7ee6dafb8e2e38f5
 
.... a while ... and maintainable is in the eye of the beholder 0)

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l


"Pegasus (MVP)" <I.can@fly.com.oz> wrote in message
news:Ov3JQ6axIHA.2208@TK2MSFTNGP04.phx.gbl...
>
> "Dean Wells (MVP)" <dwells@maskmsetechnology.com> wrote in message
> news:uzbtFFZxIHA.5652@TK2MSFTNGP06.phx.gbl...
>> Nod, I encountered the same limitation ... irritating isn't it.
>>
>> Take a look at the 'bootSwitch.cmd' script here -
>>
>> ftp://falcon.msetechnology.com/scripts/bootSwitch.cmd.txt
>>
>> ... it contains a means of resolving this behavior by exploiting an
>> all-too-often useful unicode oddity. Other ways were and probably
>> still are available though didn't give it much thought after I came
>> it that one.
>>
>> As I'm sure you know, part of the enjoyment of solving these kind of
>> annoyances is the creativity involved in making such a limited
>> environment play nicely ... this is one of my favs. to date.
>>
>> --
>> Dean Wells [MVP / Directory Services]

>
> Nicely done and highly imaginative but not my favourite.
> I'm a great user of batch files but I wonder how long it
> took you to get these lines just right and how maintainable
> they are . . .
> fsutil fsinfo drives >"%TEMP%\%~n0.$$$"
> for /f "tokens=1 delims=\ skip=10" %%d in
> ('cmd /u /c type "%TEMP%\%~n0.$$$" ^| find /v ""') do echo %%d
>
>
 
Assuming that works -- nice alternative.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l


"Esra Sdrawkcab" <admin@127.0.0.1> wrote in message
news:2Wg1k.2763$E41.2762@text.news.virginmedia.com...
> Dean Wells (MVP) wrote:
>> Nod, I encountered the same limitation ... irritating isn't it.
>>
>> Take a look at the 'bootSwitch.cmd' script here -
>>
>> ftp://falcon.msetechnology.com/scripts/bootSwitch.cmd.txt
>>
>> ... it contains a means of resolving this behavior by exploiting an
>> all-too-often useful unicode oddity. Other ways were and probably
>> still are available though didn't give it much thought after I came
>> it that one.
>>
>> As I'm sure you know, part of the enjoyment of solving these kind of
>> annoyances is the creativity involved in making such a limited
>> environment play nicely ... this is one of my favs. to date.
>>

>
>
> Ritchie in 2003 (in alt.msdos.batch.nt) gave:
>
>
> for /f "tokens=1,2" %%a in ('fsutil fsinfo drives^|more') do (
> for /f "tokens=1" %%c in ('echo/%%b %%a') do fsutil fsinfo
> drivetype %%c
> )
>
> terribly long google groups ref:
>
> http://groups.google.com/group/alt....til+fsinfo+drives+batch&#doc_7ee6dafb8e2e38f5
 
I took a second look at that syntax and decided to try it, it didn't
work (on Vista at least.) C'est la vie ...

FWIW - my guess is that the OP is trying to handle the nuls in the same
manner but piping them through more vs. find. Since I can't fully test
it ... that's a bit of a hip-shot though.

--
Dean Wells [MVP / Directory Services]
MSEtechnology
[[ Please respond to the Newsgroup only regarding posts ]]
R e m o v e t h e m a s k t o s e n d e m a i l


"Dean Wells (MVP)" <dwells@maskmsetechnology.com> wrote in message
news:eyihmTbxIHA.420@TK2MSFTNGP02.phx.gbl...
> Assuming that works -- nice alternative.
>
> --
> Dean Wells [MVP / Directory Services]
> MSEtechnology
> [[ Please respond to the Newsgroup only regarding posts ]]
> R e m o v e t h e m a s k t o s e n d e m a i l
>
>
> "Esra Sdrawkcab" <admin@127.0.0.1> wrote in message
> news:2Wg1k.2763$E41.2762@text.news.virginmedia.com...
>> Dean Wells (MVP) wrote:
>>> Nod, I encountered the same limitation ... irritating isn't it.
>>>
>>> Take a look at the 'bootSwitch.cmd' script here -
>>>
>>> ftp://falcon.msetechnology.com/scripts/bootSwitch.cmd.txt
>>>
>>> ... it contains a means of resolving this behavior by exploiting an
>>> all-too-often useful unicode oddity. Other ways were and probably
>>> still are available though didn't give it much thought after I came
>>> it that one.
>>>
>>> As I'm sure you know, part of the enjoyment of solving these kind of
>>> annoyances is the creativity involved in making such a limited
>>> environment play nicely ... this is one of my favs. to date.
>>>

>>
>>
>> Ritchie in 2003 (in alt.msdos.batch.nt) gave:
>>
>>
>> for /f "tokens=1,2" %%a in ('fsutil fsinfo drives^|more') do (
>> for /f "tokens=1" %%c in ('echo/%%b %%a') do fsutil fsinfo
>> drivetype %%c
>> )
>>
>> terribly long google groups ref:
>>
>> http://groups.google.com/group/alt....til+fsinfo+drives+batch&#doc_7ee6dafb8e2e38f5

>
>
 
"Dean Wells (MVP)" <dwells@maskmsetechnology.com> wrote in message
news:eyihmTbxIHA.420@TK2MSFTNGP02.phx.gbl...
> Assuming that works -- nice alternative.
>
> --
> Dean Wells [MVP / Directory Services]
> MSEtechnology


This line works under WinXP:
fsutil fsinfo drives|more
 
"Dean Wells (MVP)" <dwells@maskmsetechnology.com> wrote in message
news:eyihmTbxIHA.420@TK2MSFTNGP02.phx.gbl...
> Assuming that works -- nice alternative.
>
> --
> Dean Wells [MVP / Directory Services]


It appears that more.com under WinXP will translate Unicode to ASCII.
 
Pegasus (MVP) <I.can@fly.com.oz> wrote:
> This line works under WinXP:
> fsutil fsinfo drives|more


One traditional, UNIX-flavored way of getting rid of nul characters in a
string is using a TR port

fsutil fsinfo drives|tr -d \000

Or SED
fsutil fsinfo drives|sed -e "s/\x00/ /g"

But indeed, fortunately, the more trick does the same as can be readily
seen with any hex lister. Also, as was recently discussed in another
connection, the more conveniently adds a 0D 0A pair at the end of the
output, if it is missing. Well, in this case it is not.

Not that fsutil fsinfo is the only way of listing ones active drives!
The code below will give a list of devices that are _ready_

@echo off & setlocal enableextensions enabledelayedexpansion
for %%d in (a: b: c: d: e: f: g: h: i: j: k: l: m: n:
o: p: q: r: s: t: u: v: w: x: y: z:) do (
dir %%d\ > nul 2>&1
if !errorlevel! EQU 0 echo %%d
)
endlocal & goto :EOF

E.g. one might get
C:\_D\TEST>cmdfaq
c:
d:
e:

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance University of Vaasa
mailto:ts@uwasa.fi <http://www.uwasa.fi/~ts/> FI-65101, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.htm
 
Pegasus (MVP) <I.can@fly.com.oz> wrote:
> It appears that more.com under WinXP will translate Unicode to ASCII.


I doubted that it makes the suggested full conversion, so a little test.
You may wish to try

more TestFileInLatin1.txt > Outfile.txt

where Latin1 is ISO 8859-1, i.e. a Unicode 256 subset. The results do
not seem to comply.

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance University of Vaasa
mailto:ts@uwasa.fi <http://www.uwasa.fi/~ts/> FI-65101, Finland
Useful CMD script tricks http://www.netikka.net/tsneti/info/tscmd.htm
 
"Bob I" <birelan@yahoo.com> wrote in message
news:er75LzXxIHA.5472@TK2MSFTNGP06.phx.gbl...
> See "net use" and "If exist" in Windows Help and support. Also there is a
> cmd prompt group that has some pretty sharp folks(cross posting this)
>
> news://msnews.microsoft.com/microsoft.public.win2000.cmdprompt.admin
>
> joshboski wrote:
>
>> I am currently trying to write a batch file that will delete a list of
>> files from all of my network drives. The problem I am having is
>> getting the network drives. I am on a rather large network, and I
>> would like this to run on several different computers that may be
>> connected to different drives.


I have been meaning to ask advice or figure the following out myself
so I will just post my solution and describe where it has problems.

The following code WORKS on Vista, but not on 2003, nor on
XP if I recall the latter correctly.

Following is all one line (in a batch file):

@for /f "tokens=1-26 delims=\ " %%a in ('fsutil fsinfo drives') do @for %%A
in (%%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n
%%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z) do @fsutil fsinfo drivetype
%%A


=======================
Ugly but it works on Vista like this:

A: - Remote/Network Drive
C: - Fixed Drive
D: - Fixed Drive
E: - Fixed Drive
F: - CD-ROM Drive
G: - CD-ROM Drive
H: - CD-ROM Drive
J: - Remote/Network Drive
O: - Remote/Network Drive
P: - Remote/Network Drive
Q: - Remote/Network Drive
R: - CD-ROM Drive
S: - Remote/Network Drive
T: - Remote/Network Drive
U: - Remote/Network Drive
W: - Remote/Network Drive
X: - Remote/Network Drive
Y: - Remote/Network Drive
Z: - Remote/Network Drive
 
"Herb Martin" <news@learnquick.com> wrote in message
news:OSAywudxIHA.2208@TK2MSFTNGP04.phx.gbl...

Ok, based on what someone (sorry) wrote in another message this
thread I finally figured out that XP/2003 were using NULLS instead
of spaces and so now my Perl version works on both all OSes:

Following is all one line for a batch file but works if pasted or typed in
directly:

@fsutil fsinfo drives | perl -n -e "@a=split /\s|\00/ foreach (@a) {next
unless s/\\//print `fsutil fsinfo drivetype $_`}"


OK, this works on 2003 using the | more trick (with +1 /S for efficiency):


@for /f %%a in ('fsutil fsinfo drives ^| more +1 /S') do @fsutil fsinfo
drivetype %%a


The MORE trick is problematic however if your command line is SMALLER
than the list of drives -- probably not a frequent issue but it will be an
issue
on rare occasions for some people.

I also admit that I cannot figure out Dean's unicode trick (quickly enough)
to extract and use it here.

--
Herb

> I have been meaning to ask advice or figure the following out myself
> so I will just post my solution and describe where it has problems.
>
> The following code WORKS on Vista, but not on 2003, nor on
> XP if I recall the latter correctly.
>
> Following is all one line (in a batch file):
>
> @for /f "tokens=1-26 delims=\ " %%a in ('fsutil fsinfo drives') do @for
> %%A in (%%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n
> %%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z) do @fsutil fsinfo
> drivetype %%A



> =======================
> Ugly but it works on Vista like this:
>
> A: - Remote/Network Drive
> C: - Fixed Drive
> D: - Fixed Drive
> E: - Fixed Drive
> F: - CD-ROM Drive
> G: - CD-ROM Drive
> H: - CD-ROM Drive
> J: - Remote/Network Drive
> O: - Remote/Network Drive
> P: - Remote/Network Drive
> Q: - Remote/Network Drive
> R: - CD-ROM Drive
> S: - Remote/Network Drive
> T: - Remote/Network Drive
> U: - Remote/Network Drive
> W: - Remote/Network Drive
> X: - Remote/Network Drive
> Y: - Remote/Network Drive
> Z: - Remote/Network Drive
>
>
>
 
Back
Top