Use the DOS command to determine if the disk partition is NTFS formatted _DOS/BAT

Source: Internet
Author: User
One of my colleagues asked how to use commands to determine if a disk is formatted for NTFS so that you can further perform related command operations, such as converting disk formats or setting File/folder security permissions.

First reaction, you can use DiskPart. After trial, you can use the following:

echo list volume>t.txt && diskpart/s t.txt | Find "C" >result.txt && del t.txt

You then use the For statement to result.txt the output results, but the code looks overly complex and DiskPart can only run in admin mode.

So it's not realistic to use the DiskPart command. When you use cacls for file permission settings, it is found that running on a disk that is not NTFS-formatted will return 1, so you can determine whether a disk is:

cacls C:\ >nul
If%errorlevel%==1 echo C disk is not in NTFS format

However, the above method only applies to the xp/2003,win2000 no DiskPart command and runs on non-NTFS cacls returns 0, although the ver command output can be used to determine if the system is xp/ 2003, but using the cacls command under WIN2000 is difficult to determine if it is in NTFS format. It may be said that the cacls command output is null to judge, if that disk is just NTFS format, but without any security permissions, it is not easy to say.

A WMI script (Filesystem.vbs) was written:

On Error Resume Next

Const wbemflagreturnimmediately = &h10
Const wbemFlagForwardOnly = &h20

For each strComputer in arrcomputers

Set objWMIService = GetObject ("winmgmts:\\.\root\cimv2")
Set colitems = objWMIService.ExecQuery ("SELECT * from Win32_LogicalDisk", "WQL", _
wbemFlagReturnImmediately + wbemflagforwardonly)

For each objitem in colitems
WScript.Echo Objitem.caption & "" & Objitem.filesystem
Next
Next

cscript//nologon Filesystem.vbs can list all the file system formats for all the drive characters, except for those that are not available (such as CD-ROM drives), which can be modified by batch processing as follows:

cscript//nologo Filesystem.vbs | Find "C:ntfs"
If%errorlevel%=1echo C disk is not NTFS format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.