drives

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

drives

#1 Post by Mohammad_Dos » 26 Dec 2010 12:07

I want to write a batch file that save my drives information into a txt file. for example I want my batch file write these lines into "c:\drive.txt" as output:

Code: Select all

you have 4 Hard drives:
c:\  ,  d:\  ,  e:\  , f:\

and 2 cd/dvd drives:
g:\  ,  h:\

and 1 floppy drive:
a:\



sorry for my english :oops:

rfpd
Posts: 78
Joined: 06 Jul 2009 16:19
Location: Lisbon, Portugal
Contact:

Re: drives

#2 Post by rfpd » 26 Dec 2010 13:20

Try this code:

Code: Select all

@echo off
wmic logicaldisk get caption,drivetype > C:\drive.txt


Output:
Caption DriveType
C: 3
D: 3
E: 3
F: 5
H: 5

3 means hard drive
5 meand cd/drive drive

I hope i helped.

Regards, rfpd.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: drives

#3 Post by aGerman » 26 Dec 2010 19:24

Another possibility:

Code: Select all

@echo off &setlocal
for /f "tokens=1*" %%a in ('fsutil fsinfo drives') do (
  for %%c in (%%b) do (
    fsutil fsinfo drivetype %%c
  )
)
pause

Run as administrator on Win7.

Regards
aGerman

Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

Re: drives

#4 Post by Mohammad_Dos » 29 Dec 2010 10:44

rfpd wrote:Try this code:

Code: Select all

@echo off
wmic logicaldisk get caption,drivetype > C:\drive.txt


Output:
Caption DriveType
C: 3
D: 3
E: 3
F: 5
H: 5

3 means hard drive
5 meand cd/drive drive

I hope i helped.

Regards, rfpd.

and 2 means flash memory or ram reader or external usb drive
thank u

Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

Re: drives

#5 Post by Mohammad_Dos » 29 Dec 2010 10:48

aGerman wrote:Another possibility:

Code: Select all

@echo off &setlocal
for /f "tokens=1*" %%a in ('fsutil fsinfo drives') do (
  for %%c in (%%b) do (
    fsutil fsinfo drivetype %%c
  )
)
pause

Run as administrator on Win7.

Regards
aGerman

but I have win xp

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: drives

#6 Post by aGerman » 29 Dec 2010 10:59

Well then a simple double click should run the script. Didn't you try it?

Regards
aGerman

Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

Re: drives

#7 Post by Mohammad_Dos » 01 Jan 2011 04:17

aGerman wrote:Well then a simple double click should run the script. Didn't you try it?

Regards
aGerman

yes, of course
dont work in win xp



I have a question:
how to replace these words in the c:\Drive.txt ?


Caption DriveType
C: 3 "3"----->"Hard Disk Drive"
D: 3 "3"----->"Hard Disk Drive"
E: 3 "3"----->"Hard Disk /Drive"
F: 5 "5"----->"CD/DVD Drive"
H: 5 "5"----->"CD/DVD Drive"
L: 2 "2"----->"External USB Drive"

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: drives

#8 Post by aGerman » 01 Jan 2011 08:45

Mohammad_Dos wrote:
aGerman wrote:Well then a simple double click should run the script. Didn't you try it?

Regards
aGerman

yes, of course
dont work in win xp

Strange :? I remember that it worked for me on XP.

Mohammad_Dos wrote:I have a question:
how to replace these words in the c:\Drive.txt ?

You could already write the Drive.txt file with the replaced type numbers.

Code: Select all

@echo off &setlocal enabledelayedexpansion

set "DriveType_1=Unknown"
set "DriveType_2=Removeable Drive"
set "DriveType_3=Local Hard Disk"
set "DriveType_4=Network Hard Disk"
set "DriveType_5=Compact Disc"
set "DriveType_6=RAM Disk"

(
  for /f "tokens=1,2" %%a in ('wmic logicaldisk get caption^,drivetype') do (
    set "Drive=%%a        "
    set "TypeName="
    set "TypeName=!DriveType_%%b!"
    if not defined TypeName set "TypeName=%%b"
    echo(!Drive:~0,8!!TypeName!
  )
)>C:\Drive.txt



Regards
aGerman

Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

Re: drives

#9 Post by Mohammad_Dos » 02 Jan 2011 07:55

aGerman wrote:Another possibility:

Code: Select all

@echo off &setlocal
for /f "tokens=1*" %%a in ('fsutil fsinfo drives') do (
  for %%c in (%%b) do (
    fsutil fsinfo drivetype %%c
  )
)
pause

Run as administrator on Win7.

Regards
aGerman

now worked!!!! :!: :?:

but not completly:

Code: Select all

A:\ - Removable Drive

Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

Re: drives

#10 Post by Mohammad_Dos » 02 Jan 2011 08:04

aGerman wrote:

Code: Select all

@echo off &setlocal enabledelayedexpansion

set "DriveType_1=Unknown"
set "DriveType_2=Removeable Drive"
set "DriveType_3=Local Hard Disk"
set "DriveType_4=Network Hard Disk"
set "DriveType_5=Compact Disc"
set "DriveType_6=RAM Disk"

(
  for /f "tokens=1,2" %%a in ('wmic logicaldisk get caption^,drivetype') do (
    set "Drive=%%a        "
    set "TypeName="
    set "TypeName=!DriveType_%%b!"
    if not defined TypeName set "TypeName=%%b"
    echo(!Drive:~0,8!!TypeName!
  )
)>C:\Drive.txt



Regards
aGerman

good. output:

Code: Select all

Please  wait
A:      Removeable Drive
C:      Local Hard Disk
D:      Local Hard Disk
E:      Local Hard Disk
F:      Local Hard Disk
G:      Compact Disc
H:      Local Hard Disk
I:      Compact Disc
K:      Removeable Drive

but I dont want "please wait". is it possible?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: drives

#11 Post by aGerman » 02 Jan 2011 08:43

Honestly I have no idea where this line is comming from.
My head line is
Caption DriveType


Probably the wmic command is outputting this line while it collects the data. You could try to skip the first line.

Code: Select all

@echo off &setlocal enabledelayedexpansion

set "DriveType_1=Unknown"
set "DriveType_2=Removeable Drive"
set "DriveType_3=Local Hard Disk"
set "DriveType_4=Network Hard Disk"
set "DriveType_5=Compact Disc"
set "DriveType_6=RAM Disk"

(
  for /f "skip=1 tokens=1,2" %%a in ('wmic logicaldisk get caption^,drivetype') do (
    set "Drive=%%a        "
    set "TypeName="
    set "TypeName=!DriveType_%%b!"
    if not defined TypeName set "TypeName=%%b"
    echo(!Drive:~0,8!!TypeName!
  )
)>C:\Drive.txt



Regards
aGerman

Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

Re: drives

#12 Post by Mohammad_Dos » 03 Jan 2011 04:17

worked :wink:
output:

Code: Select all

A:      Removeable Drive
C:      Local Hard Disk
D:      Local Hard Disk
E:      Local Hard Disk
F:      Local Hard Disk
G:      Compact Disc
H:      Local Hard Disk
I:      Compact Disc

Post Reply