Unable to delete files or folders on NTFS disk (a detailed description of the various scenarios for Windows files)

Source: Internet
Author: User
Tags posix knowledge base

Introduction This article describes the reasons why you may not be able to delete files or folders on NTFS file system volumes, and how to resolve this issue by analyzing the different causes for this problem. More informationNote: Internally, NTFS handles folders as special types of files. Therefore, the word "file" in this article may refer to a file or a folder. Cause 1: The file uses an ACL If a file uses an Access control list (ACL), you may not be able to delete the file. To resolve this issue, change the permissions on the file. You may need to have ownership of these files to change permissions.

Administrators have the implicit ability to take ownership of any file, even if they are not explicitly granted any permissions on the file. File owners have the implicit ability to modify file permissions, even if they are not explicitly granted any permissions on the file. Therefore, you may need to take ownership of a file, give yourself permission to delete the file, and then delete the file. Cannot use certain security tools to display or modify permissions because the file uses an irregular ACLTo work around this issue, use another tool (for example, an updated version of Cacls.exe).

Depending on the owning type, access control entries (Aces) in the ACL have a specific order of precedence. For example, an access-denied ACE is typically preceded by an ACE that grants access. However, we cannot prevent a program from writing ACLs that arrange aces in any order. In some earlier versions of Windows, there was a problem when Microsoft windows tried to read these "nonstandard" ACLs. Sometimes, these ACLs cannot be modified correctly by using the Microsoft Windows Explorer Graphical security editor. This issue has been corrected in later versions of Windows. If you are experiencing this problem, use the latest version of Cacls.exe. Even if an existing ACL cannot be displayed or edited, you can write a new ACL that allows you to access the file. Cause 2: The file is in use If the file is in use, you may not be able to delete it. To resolve this issue, determine the process that has the open handle, and then close the process.

Depending on how the file is opened (for example, open with exclusive access rather than shared access), you may not be able to delete the files in use. At any time, you can use a variety of tools to help determine the process that owns the open handle to the file. To learn more about the tools that can help determine the process that owns the file open handle, click the following article number to view the article in the Microsoft Knowledge Base:

242131 How to display a list of processes that have open files

172710 How to use the OH tool in the Windows NT 4.0 Resource Kit

The symptoms of this problem may vary. You can use the Delete command to delete a file, but the file is not actually deleted until the process that opened the file releases the file. Additionally, you may not be able to access the Security dialog box for files that are being deleted. To resolve this issue, determine the process that has the open handle, and then close the process. Cause 3: File system corruption makes it impossible for you to access this file If the file system is corrupted, you may not be able to delete the file. To resolve this issue, run the Chkdsk utility on the disk volume to correct any errors that exist.

Bad zones on the disk, other hardware failures, or software errors can corrupt the file system and cause problems with the file. Typical operations can fail in different ways. When the file system detects corruption, it logs an event in the event log, and you typically receive a message that prompts you to run Chkdsk. Depending on the nature of the corruption, CHKDSK may or may not be able to recover file data, but Chkdsk can return the file system to an internally consistent state. For additional information about how to use the Chkdsk utility, click the following article number to view the article in the Microsoft Knowledge Base: 176646 error Message: The file or directory is corrupt ... (file or directory is corrupted ...) )

187941 explanation of CHKDSK and the new/C and/I switches

Cause 4: The file is in a deeper path than the MAX_PATH characterIf there is a problem with the file path, you may not be able to open, edit, or delete the file. Solution 1: Access the file using an automatically generated 8.3 nameTo resolve this issue, you may need to access the file using an automatically generated 8.3 name. This is probably the easiest solution if the path is deep because the folder name is too long. If the 8.3 path is too long, or 8.3 names are disabled on the volume, go to Solution 2. For additional information about disabling 8.3 file names on NTFS volumes, click the following article number to view the article in the Microsoft Knowledge Base:121007 How to disable the creation of 8.3 names on NTFS partitions

Solution 2: Rename or move the folder with deep pathRename the folder so that the path depth of the destination file does not exceed MAX_PATH. To do this, start with the root folder (or any other convenient location), and then rename the folders to shorten their names. If this step does not resolve the issue (for example, if the file has a depth of more than 128 folders), go to Solution 4. Solution 3: Map the drive to a folder in the path structure maps a drive to a folder in the path structure of a catalog file or folder. This method can shorten the actual path.

For example, suppose you have a path that resembles the following structure: \\servername\subfoldername1\subfoldername2\subfoldername3\subfoldername4\ ... in this path, the total number of characters exceeds 255. To shorten the length of the path to 73 characters, map the drive to a SubfolderName4. Solution 4: Use a network share with the same depth as the folderif solution 1, 2, or 3 is inconvenient or does not resolve the issue, create a network share that is as deep in the folder tree as possible, and then rename the folder by accessing the share. Solution 5: Use a tool that can traverse deep pathsMany Windows programs expect a maximum path length of less than 255 characters. Therefore, these programs only allocate enough internal storage to handle these typical paths. NTFS does not have this limitation, and it can handle a much longer path than this.

You may experience this problem if you create a share in a folder structure that is already quite deep, and then create a deep structure under this location by using this share. Some tools that perform local operations on the folder tree may not traverse the entire folder tree starting from the root folder. You may want to use these tools in a special way so that they can traverse the shared location. (The CreateFile API documentation describes a way to traverse the entire folder tree in this case.) )

In general, you can manage these files by using the software that created the files. If you have a program that can create files that are more than MAX_PATH, you can typically use this same program to delete or manage these files. You can typically delete files created on this same share by using a share. Cause 5: A reserved name in the Win32 namespace is included in the file name If you include a reserved name in the Win32 namespace (for example, "LPT1") in the file name, you may not be able to delete the file. To resolve this issue, use a non-WIN32 program to rename the file. You can use the POSIX tool or any other tool that uses the appropriate internal syntax to work with this file.

In addition, if you specify the path to a file using a specific syntax, you might be able to use some built-in commands to bypass the typical WIN32 reserved name check. For example, if you use the Del command in Windows XP, you can delete a file named "lpt1" if you specify the full path to the file by using the following specific syntax: del \\?\c:\path_to_file\lpt1 For more information about removing files with reserved names under Windows NT and Windows 2000, click the following article number to view the article in the Microsoft Knowledge Base:

120716 How to delete a file with a reserved name in Windows

For more information about removing files with reserved names under Windows XP, click the following article number to view the article in the Microsoft Knowledge Base:

315226 How to delete a file with a reserved name in Windows XP

If you use a typical WIN32 CreateFile mechanism to open a handle to a file, some file names are reserved for legacy DOS devices. For backwards compatibility, these file names are not allowed, and they cannot be created using typical Win32 file transfer. However, this issue is not a limitation of NTFS.

You might be able to use the WIN32 program to bypass the typical name checks that are performed when you create (or delete) a file by using the same technique used to traverse a folder that is more than MAX_PATH. In addition, some POSIX tools do not accept these name checks. Cause 6: The file name includes an invalid name in the Win32 namespaceIf the file name includes an invalid name, you may not be able to delete it (for example, a file name has a trailing space, or a trailing period, or the file name consists of only one space). To resolve this issue, remove the file with a tool that uses the appropriate internal syntax. You can use the "\\?\" syntax for some tools to manipulate these files, for example:del "\\?\c:\path_to_file_that contains a trailing space.txt" The cause of this problem is similar to cause 4. However, if you use a typical WIN32 syntax to open a file with trailing spaces or trailing periods in the name, trailing spaces or periods are removed before the actual file is opened. Therefore, if you have two files in the same folder named "AFile.txt" and "AFile.txt" (note the spaces after the file name), if you try to open the second file with a standard Win32 call, the first file will actually open. Similarly, if the file name is only "" (a space character), when you try to open it by using a standard Win32 call, the file's parent folder is actually opened. In this situation, if you try to change the security settings on these files, you cannot change them, or you can accidentally change the settings on other files. If this behavior occurs, you may think that you have permission to operate on a file that actually has a restrictive ACL. Multiple reasonsSometimes, you may encounter several of these reasons at the same time, which makes the process of deleting files more complex. For example, if you are logged on as a computer administrator, you may not be able to delete the file if you encounter cause 1 at the same time (you do not have permission to delete the file) and cause 5 (the file name contains a trailing character that causes the files access to redirect to another file or to a nonexistent file). If you try to resolve the issue of cause 1 by taking ownership of the file and adding permissions, you may still be unable to delete the file because the ACL editor in the user interface cannot access the correct file because of reason 6.

In this case, you can use the Subinacl utility and the /onlyfile switch (which is included in the resource Kit) to change the file ownership and operation permissions (inaccessible if not changed), for example: subinacl/onlyfile "\\?\c:\path_to_problem_file"/setowner=domain\administrator/grant=domain\ administrator=f Note: This command is a one-line command, where line breaks are made for readability.

This example command line modifies a C: \ path_to_problem_file file that contains trailing spaces so that the domain\Administrator account becomes the owner of the file and has full control over the file. You can now delete this file by using the Del command and the same "\\?\" syntax. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

319368 you receive an "Access Denied" error message when you delete a folder from a mounted drive

Property

Article id:320081-Last review: September 23, 2011-Revision: 1

The information in this article applies to:Microsoft Windows Server 2003, Datacenter Edition for itanium-based Systems, Microsoft Windows Server 2003, Enterprise Edi tion for itanium-based Systems, Microsoft Windows Server 2003 Standard Edition, Microsoft Windows Server 2003 Datacenter E dition, Microsoft Windows Server 2003 Enterprise Edition, Microsoft Windows Server 2003 Web Edition, Microsoft Windows Sma ll Business Server 2003 Premium Edition, Microsoft Windows Small Business Server 2003 Standard Edition, Microsoft Windows XP Professional Edition, Microsoft Windows XP Home Edition, Microsoft Windows Server, Microsoft Windows Server, Microsoft Windows Professional Edition, Microsoft Windows Advanced Server, Limited Edition, Microsoft Window s Datacenter Server Limited Edition

Https://support.microsoft.com/zh-cn/help/320081/you-cannot-delete-a-file-or-a-folder-on-an-ntfs-file-system-volume

Unable to delete files or folders on NTFS disk (a detailed description of the various scenarios for Windows files)

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.