carstorm
carstorm

Reputation: 141

How can I use batch to determine if a computer is using FAT32 or NTFS?

How can I use batch to determine if a computer is using FAT32 or NTFS and is this even possible.

Upvotes: 5

Views: 4039

Answers (5)

Sam Denty
Sam Denty

Reputation: 4085

This is an old question, but here is my answer to get a drive file system and then set it as a variable %DriveType%

Replace C: with the drive of your choice and use one of the below commands depending on where it's used:

For use in a batch file:

@echo off
for /f "tokens=5" %%a in ('@fsutil fsinfo volumeinfo c:^|findstr /B "File System Name : "') do (@set DriveType=%%a)
echo %DriveType%
pause

For use in the Command Prompt:

for /f "tokens=5" %a in ('@fsutil fsinfo volumeinfo c:^|findstr /B "File System Name : "') do @set DriveType=%a

Upvotes: 3

npocmaka
npocmaka

Reputation: 57272

One more way (requires admin permissions):

fltmc volumes | find ":"

This will list file system type of all drives.You can filter by drive using for instance "C:" instead of ":"

Upvotes: 2

user240217
user240217

Reputation: 132

Try This:

@echo off
SET VOLUME_LETTER=c:
fsutil fsinfo volumeinfo %VOLUME_LETTER% 2>NUL | find /I /N "NTFS">NUL

if [%ERRORLEVEL%] == [0] echo NTFS

Upvotes: 2

Alex K.
Alex K.

Reputation: 175876

It looks like attempting to use an alternate file stream (file.name:strmname) on a FAT volume fails, so how about:

@echo off
set drv=C:
set file=temp.temp

if exist %drv%\%file% del %drv%\%file%
@echo 1 > %drv%\%file%:stream
if not exist %drv%\%file% goto FAT

:NTFS
echo is NTFS
del %drv%\%file%
goto eof

:FAT
echo is FAT
goto eof

:eof

Upvotes: 5

paxdiablo
paxdiablo

Reputation: 882048

There's a few ways you can do this.

A primitive way is to run chkdsk on the volume you're interested in and capture the output. Part of that output indicates whether the disk is NTFS or not. Unfortunately, that does more than what you expect and may take some time.

Similarly, you can parse the output of fsutil fsinfo volumeinfo c:\ which is something like:

Volume Name : Primary
Volume Serial Number : 0x4f70e7b
Max Component Length : 255
File System Name : NTFS
Supports Case-sensitive filenames
Preserves Case of filenames
Supports Unicode in filenames
Preserves & Enforces ACL's
Supports file-based Compression
Supports Disk Quotas
Supports Sparse files
Supports Reparse Points
Supports Object Identifiers
Supports Encrypted File System
Supports Named Streams

By extracting the file system name, you could find out what you need.

A slightly less primitive way is to use VBScript with WMI to walk the device array, checking each volume that you're interested in.

The Win32_LogicalDisk class (available in Windows 2000 onwards) has a FileSystem attribute which indicates this and you could use the following code as a basis:

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colVols = objWMIService.ExecQuery ("select * from Win32_LogicalDisk")
For Each objVol in colVols
     MsgBox objVol.Name & " : " & objVol.FileSystem
Next

Upvotes: 8

Related Questions