How can I use batch to determine if a computer is using FAT32 or NTFS and is this even possible.
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
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
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
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
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
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 ":"
© 2022 - 2024 — McMap. All rights reserved.
chkdsk /c D:
will tell you what filesystem D: drive has been formatted with. – Neal