Causes and workarounds for files that cannot be deleted

Source: Internet
Author: User
Tags reserved win32 file permissions

reason one: The file is in use

One of the frequently encountered problems when deleting files is that the file is in use and cannot be deleted. If you try to delete a file that is open with exclusive access instead of shared access, and you are working with the files, an error message appears: "Cannot delete xxx: The file is being used by another person or program." The other is the ability to delete a file using the Delete command, but the file is not actually deleted until the process of the open file releases the file.

To resolve these issues, you need to determine the process that owns the file open handle, and then close the process. In previous windows, we could use the Oh.exe of the resource Kit. In XP, however, the installed Support tools are not Oh.exe. However, XP provides a new Openfiles.exe command-line tool that can report the individual files that the process opens. Similar to Oh.exe, Openfiles.exe also requires that system kernel monitoring be turned on, which consumes some memory and reduces the performance of system operations. The command to turn on system monitoring is "Openfiles/localon", which enables the system global flag "maintain object list" and requires a system restart to take effect. After restarting the system, you can see the list of open files for each process by executing "Openfiles" with no parameters at the command prompt.

 Cause two: File system corruption

Bad zones, other hardware failures, or software errors on the disk can corrupt the file system and cause problems with the file and cannot be deleted. Typical operations can fail in different ways, and you typically receive a message that prompts you to run Chkdsk when a file system corruption is detected.

If you encounter this situation, you can run the Chkdsk utility on the disk volume to correct any errors that exist. Depending on the nature of the corruption, CHKDSK may be able to recover file data and may not be recoverable, but Chkdsk can return the file system to an internally consistent state. For the commands and parameters of the Chkdsk utility, you can execute "chkdsk/?" at the command prompt. Inspection.

 Reason three: The file uses the Access control list

If a file uses an Access control list (Access Controllist, referred to as an ACL) and the operator does not have the appropriate permissions, a "Access denied" hint may appear when the file is deleted.

Typically, an administrator has the implicit ability to take ownership of any file, and the file owner also has the implicit ability to modify file permissions. However, these default permissions can be modified.

To resolve an issue in which the file cannot be deleted because of an ACL, you must be logged on as a user with the appropriate permissions, or you can give yourself permission to delete the file before deleting the file. It is important to note that the operator must have ownership of these files to change permissions. If the file uses an irregular ACL and cannot use some security tools to display or modify its permissions, you can try using the command-line tool Cacls.exe to modify it.

  Reason four: The file name uses a reserved name

It is well known that names such as aux and LPT1 are reserved for legacy DOS devices. For backwards compatibility, these file names are not allowed in Windows, and they cannot be created using typical Win32 file transfer. Conversely, if the file name is a reserved name in the Win32 namespace, you may also be unable to delete the files.

To resolve this type of problem, you can rename or delete the file under Linux or other non-Windows operating systems. In addition, if you can specify the path to the file using a specific syntax, you can also use some built-in commands to bypass the typical WIN32 reserved name check. For example, you can delete a file named "lpt1" by using the following command in WindowsXP ("?" after the Del command). To prevent Windows from checking the legality of file names): Del c:[/url] file path LPT1.

 Reason five: Invalid file name

If you include an invalid name in the file name, such as a trailing space for the file name, or a trailing period, or if the file name consists of only a single space, you may not be able to delete it. It is worth mentioning that 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 "File.txt" and "File.txt" (note the spaces after the second file name), when you open the second file with a standard Win32 call, the first file is actually opened. 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 may accidentally change the settings on other files.

Similar to the method for resolving file names using reserved names, you can delete this file using an appropriate internal syntax. For example, to delete a file that contains trailing spaces, you can use the following command: Del C: File path (file name for trailing spaces)

  Cause six: The file path is too deep to access

The file is in a deeper path than the maximum path character count (MAX_PATH), which may cause the file to be inaccessible, which is, of course, rare. If the path is deep because the folder name is too long, the easiest solution is to use the automatically generated 8.3 name to access the file. If the 8.3 path is too long, you can rename the folders from the root folder and shorten their names so that the path depth of the destination file does not exceed MAX_PATH. If the file depth exceeds 128 folders, you can access the file by creating a network share that is as deep in the folder tree as possible, and then accessing the share.

In general, you can manage these files by using the software that created the files if you encounter situations where the file path is too deep to be accessible. That is, if you have a program that can create files that are more than MAX_PATH, we can also use the program to manage those files. In addition, files for deep structures created through network shares can also be deleted by using the same share.

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.