Use the doscommand to determine whether the disk partition is in NTFS format

Source: Internet
Author: User

A colleague asked how to use commands to determine whether the disk is in NTFS format for further command operations, such as converting the disk format or setting file/folder security permissions.

First, you can use diskpart. It can be used as follows:

Echo list volume> t.txt & diskpart/s t.txt | find "C"> result.txt & del t.txt

Then, use the for sentence to perform segmentation judgment on the output result result.txt. However, this code looks too complex and diskpart can only run in administrator mode.

Therefore, it is unrealistic to use the diskpart command. When you use cacls to set file permissions, it is found that 1 is returned when you run on a non-NTFS disk. Therefore, 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 XP/2003, WIN2000 does not have the DISKPART command, and running CACLS on non-NTFS returns 0, although you can use the ver command output to determine whether the system is XP/2003, however, it is difficult to determine whether the cacls command is in NTFS format in WIN2000. It may be said that the cacls command output is null to judge, if the disk is in NTFS format, but does not have any security permissions, it is hard to say.

Write a WMI script (FileSystem. vbs ):

On Error Resume Next

Const wbemFlagReturnImmediately = & h10
Const wbemFlagForwardOnly = & h20

For Each strComputer In arrComputers

Set ob1_miservice = GetObject ("winmgmts: \. \ root \ CIMV2 ")
Set colItems = ob1_miservice. 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 the file system formats of all drive letters. Except for unavailable (such as the optical drive without a cd), the fixed modifiable batch processing is as follows:

Cscript // nologo filesystem. vbs | find "C: NTFS"
If % errorlevel % = 1 echo C disk is not in 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.