Jump to content

Batch file to show Network drives


Recommended Posts

Guest joshboski
Posted

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.

  • Replies 49
  • Created
  • Last Reply
Guest Bob I
Posted

Re: Batch file to show Network 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)

 

http://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.

Guest joshboski
Posted

Re: Batch file to show Network 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)

>

> http://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

Guest Pegasus \(MVP\)
Posted

Re: Batch file to show Network 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)

>>

>> http://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.

Guest Pegasus \(MVP\)
Posted

Re: Batch file to show Network 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)

>>

>> http://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

Guest Dean Wells \(MVP\)
Posted

Re: Batch file to show Network drives

 

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)

>

> http://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.

>

Guest Pegasus \(MVP\)
Posted

Re: Batch file to show Network 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?

Guest Timo Salmi
Posted

Re: Batch file to show Network drives

 

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

Guest Dean Wells \(MVP\)
Posted

Re: Batch file to show Network drives

 

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?

>

>

Guest Pegasus \(MVP\)
Posted

Re: Batch file to show Network drives

 

 

"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

Guest Esra Sdrawkcab
Posted

Re: Batch file to show Network drives

 

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.msdos.batch.nt/tree/browse_frm/thread/9f10aa49e2ebd42f/8c23a39f7b68a048?rnum=1&q=fsutil+fsinfo+drives+batch&_done=%2Fgroup%2Falt.msdos.batch.nt%2Fbrowse_frm%2Fthread%2F9f10aa49e2ebd42f%2F7ee6dafb8e2e38f5%3Flnk%3Dst%26q%3Dfsutil%2Bfsinfo%2Bdrives%2Bbatch%26#doc_7ee6dafb8e2e38f5

Guest Dean Wells \(MVP\)
Posted

Re: Batch file to show Network drives

 

.... 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

>

>

Guest Dean Wells \(MVP\)
Posted

Re: Batch file to show Network drives

 

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.msdos.batch.nt/tree/browse_frm/thread/9f10aa49e2ebd42f/8c23a39f7b68a048?rnum=1&q=fsutil+fsinfo+drives+batch&_done=%2Fgroup%2Falt.msdos.batch.nt%2Fbrowse_frm%2Fthread%2F9f10aa49e2ebd42f%2F7ee6dafb8e2e38f5%3Flnk%3Dst%26q%3Dfsutil%2Bfsinfo%2Bdrives%2Bbatch%26#doc_7ee6dafb8e2e38f5

Guest Dean Wells \(MVP\)
Posted

Re: Batch file to show Network drives

 

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.msdos.batch.nt/tree/browse_frm/thread/9f10aa49e2ebd42f/8c23a39f7b68a048?rnum=1&q=fsutil+fsinfo+drives+batch&_done=%2Fgroup%2Falt.msdos.batch.nt%2Fbrowse_frm%2Fthread%2F9f10aa49e2ebd42f%2F7ee6dafb8e2e38f5%3Flnk%3Dst%26q%3Dfsutil%2Bfsinfo%2Bdrives%2Bbatch%26#doc_7ee6dafb8e2e38f5

>

>

Guest Pegasus \(MVP\)
Posted

Re: Batch file to show Network drives

 

 

"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

Guest Pegasus \(MVP\)
Posted

Re: Batch file to show Network drives

 

 

"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.

Guest Timo Salmi
Posted

Re: Batch file to show Network drives

 

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

Guest Timo Salmi
Posted

Re: Batch file to show Network drives

 

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

Guest Herb Martin
Posted

Re: Batch file to show Network drives

 

 

"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)

>

> http://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

Guest Herb Martin
Posted

Re: Batch file to show Network drives

 

 

 

"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

>

>

>

Guest Esra Sdrawkcab
Posted

Re: Batch file to show Network drives

 

Timo Salmi wrote:

> 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

>

Mmm I see Ms have dropped the hoary "Abort Retry Ignore" message

Guest Herb Martin
Posted

Re: Batch file to show Network drives

 

 

The following works on 2003 and Vista but is really slow (at least

on 2003) when it encounters a disconnected network drive letter that *IS*

mapped:

 

ALL ONE LINE FOLLOWING:

 

for %%a 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 @if

exist %%a:\lpt1 @fsutil fsinfo drivetype %%a:

 

 

This takes advantage of the pseudo file "LPT1" which has been

around since early DOS to prevent confusion with file names

that are the same as the Print device name (IIRC).

 

"if exist c:\lpt1" is TRUE if c:\ exists otherwise it is false.

 

I like the " | more +1 /S" best I think for 2003.

 

I thought I found a trick with FindStr that would convert the nulls

to dots, but it was just cosmetic on the screen and the pipe didn't

do that.

 

The following LOOKS good on the screen but isn't useful as far

as I can tell:

 

fsutil fsinfo drives | findstr \\

 

Is there anyway to get a NULL into "delims="????

> "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

>>

>>

>>

>

>

Guest Herb Martin
Posted

Re: Batch file to show Network drives -- simple methods for XP/2003/Vista work now

 

Re: Batch file to show Network drives -- simple methods for XP/2003/Vista work now

 

Ok (after obsessing a bit) this work on (at least) XP/2003:

 

[Following is all one line for a batch file: drives.cmd]

 

@for /f %%a in ('fsutil fsinfo drives ^| find "\"') do @fsutil fsinfo

drivetype %%a

 

 

And this version works on (at least) Vista:

[Following is all one line for a batch file: drives.cmd]

 

@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

 

 

Oddly enought the XP/2003 is not less awkward.

 

Output looks like this (with fix width font so it lines up there):

 

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

V: - 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:%23ufNxshxIHA.3968@TK2MSFTNGP04.phx.gbl...

>

> The following works on 2003 and Vista but is really slow (at least

> on 2003) when it encounters a disconnected network drive letter that *IS*

> mapped:

>

> ALL ONE LINE FOLLOWING:

>

> for %%a 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 @if

> exist %%a:\lpt1 @fsutil fsinfo drivetype %%a:

>

>

> This takes advantage of the pseudo file "LPT1" which has been

> around since early DOS to prevent confusion with file names

> that are the same as the Print device name (IIRC).

>

> "if exist c:\lpt1" is TRUE if c:\ exists otherwise it is false.

>

> I like the " | more +1 /S" best I think for 2003.

>

> I thought I found a trick with FindStr that would convert the nulls

> to dots, but it was just cosmetic on the screen and the pipe didn't

> do that.

>

> The following LOOKS good on the screen but isn't useful as far

> as I can tell:

>

> fsutil fsinfo drives | findstr \\

>

> Is there anyway to get a NULL into "delims="????

>

>> "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

>>>

>>>

>>>

>>

>>

>

>

Guest Dean Wells \(MVP\)
Posted

Re: Batch file to show Network drives

 

It's always strange to me just how much pleasure I seem to derive from

working in this (let's face it) old & crappy little shell ... but,

seemingly like the rest of you, I'm quite happy doing so and will

readily jump on the 'let's see how many alternatives there are'

band-wagon whilst striving for the apparent golden-egg of batch syntax:

that ever elusive 'let's make it a one-liner.' Anyway, I came up with

this improvement on my original syntax, it too limits the number of

iterations resulting from the for loop to only those necessary (note

that it's a one-liner; well, sorta) -

 

fsutil fsinfo drives >"%TEMP%\%~n0.$$$" && for /f %%d in ('cmd /u /c

type "%TEMP%\%~n0.$$$" ^| more +11 ^| findstr "[A-Z]"') do fsutil fsinfo

drivetype %%d: & del "%TEMP%\%~n0.$$$" 2>nul

 

--

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

 

 

"Herb Martin" <news@learnquick.com> wrote in message

news:OSAywudxIHA.2208@TK2MSFTNGP04.phx.gbl...

>

> "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)

>>

>> http://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

>

>

>

Guest foxidrive
Posted

Re: Batch file to show Network drives

 

On Wed, 4 Jun 2008 09:14:38 -0400, "Dean Wells \(MVP\)"

<dwells@maskmsetechnology.com> wrote:

>It's always strange to me just how much pleasure I seem to derive from

>working in this (let's face it) old & crappy little shell ... but,

>seemingly like the rest of you, I'm quite happy doing so and will

>readily jump on the 'let's see how many alternatives there are'

>band-wagon whilst striving for the apparent golden-egg of batch syntax:

>that ever elusive 'let's make it a one-liner.'

 

Here's more conventional syntax in my contribution after following this

thread:

 

 

@echo off

for /f "delims=" %%a in ('fsutil fsinfo drives^|more') do call :next "%%a"

goto :EOF

:next

set "var=%~1"

set "var=%var:~-3,2%"

fsutil fsinfo drivetype %var%

shift

if not %1.==. goto :next


×
×
  • Create New...