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

5

5

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

Doriandoric answered 9/8, 2011 at 11:57 Comment(3)
A single computer can have multiple hard disk which can each have multiple file systems. It depends on how the hard disk has been partitioned and formatted. chkdsk /c D: will tell you what filesystem D: drive has been formatted with.Neal
There are more than two file systems, are you looking for a specific feature like security, hardlinks, junctions or alternate data streams?Vulture
@Vulture I want to just get the type of file system and put it to a variable. The reason is that in NTFS it uses RECYCLER but FAT32 uses RECYCLEDDoriandoric
E
5

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
Excepting answered 9/8, 2011 at 12:23 Comment(1)
What about network drives?Lebkuchen
M
8

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
Miceli answered 9/8, 2011 at 12:7 Comment(0)
E
5

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
Excepting answered 9/8, 2011 at 12:23 Comment(1)
What about network drives?Lebkuchen
H
3

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
Hieroglyphic answered 26/8, 2015 at 17:20 Comment(0)
M
2

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
Mcelhaney answered 9/8, 2011 at 12:31 Comment(2)
I want to just get the type of file system and put it to a variable. The reason is that in NTFS it uses RECYCLER but FAT32 uses RECYCLEDDoriandoric
I just gave you an example of the %ERRORLEVEL% value when it found the NTFS word. You can change the "echo NTFS" command to whatever you want.Mcelhaney
A
2

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

Ashtonashtonunderlyne answered 8/9, 2013 at 9:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.