如何使用批处理来确定计算机使用的是 FAT32 还是 NTFS?

发布于 2024-11-28 22:21:58 字数 45 浏览 1 评论 0原文

如何使用批处理来确定计算机是否使用 FAT32 还是 NTFS,这是否可能。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

Saygoodbye 2024-12-05 22:21:58

有几种方法可以做到这一点。

一种原始方法是在您感兴趣的卷上运行 chkdsk 并捕获输出。该输出的一部分指示磁盘是否为 NTFS。不幸的是,这超出了您的预期,并且可能需要一些时间。

同样,您可以解析 fsutil fsinfo volumeinfo c:\ 的输出,如下所示:

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

通过提取文件系统名称,您可以找到您需要的内容。

稍微不那么原始的方法是使用带有 WMI 的 VBScript 来遍历设备数组,检查您感兴趣的每个卷。

Win32_LogicalDisk 类(在 Windows 2000 及以上版本中可用)有一个 FileSystem 属性表明了这一点,您可以使用以下代码作为基础:

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

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
沙与沫 2024-12-05 22:21:58

看起来尝试在 FAT 卷上使用备用文件流 (file.name:strmname) 会失败,那么如何:

@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

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
深白境迁sunset 2024-12-05 22:21:58

这是一个老问题,但这是我的答案,获取驱动器文件系统,然后将其设置为变量 %DriveType%

C: 替换为您选择的驱动器,并根据使用位置使用以下命令之一:

用于批处理文件:

@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 /f "tokens=5" %a in ('@fsutil fsinfo volumeinfo c:^|findstr /B "File System Name : "') do @set DriveType=%a

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
蓝颜夕 2024-12-05 22:21:58

试试这个:

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

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

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
行雁书 2024-12-05 22:21:58

另一种方式(需要管理员权限):

fltmc volumes | find ":"

这将列出所有驱动器的文件系统类型。您可以使用例如“C:”​​而不是“:”按驱动器进行过滤

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文