Reasons for the failure to delete files and suggestions (1)

  

Analysis and recommendations for the reasons why files cannot be deleted

In the process of using Windows, we will encounter various problems. Even the easiest way to delete a file can be troublesome, either the system prompts “The file is being used by another person or program”, or the report is “Access denied” <;hellip;… if you have encountered In this case, let's look at the reasons for these problems?

Reason one: The file is in use

One problem that is often encountered when deleting files is that the file is Cannot be deleted. If you attempt to delete a file that was opened for exclusive access instead of shared access and is in use, an error message will appear: "Unable to delete xxx: the file is being used by another person or program". In the other case, the delete command can be used to delete the file, but the file is not actually deleted until the process that opened the file releases the file.

To solve the above problem, you need to determine the process that owns the file open handle and then close the process. In previous Windows, we could use the resource kit's Oh.exe. But in XP, the installed Support Tools does not have Oh.exe. However, XP provides a new Openfiles.exe command-line tool that reports on individual files opened by the process. Similar to Oh.exe, Openfiles.exe also requires system kernel monitoring to be turned on, which consumes some memory and reduces the performance of system operations. The command to open the system monitoring is "Openfiles/localon", which will enable the system global flag "Maintenance Object List", which needs to be restarted to take effect. After restarting the system, execute “ldfiles” with no parameters at the command prompt to see a list of open files for each process.

Cause 2: File System Corruption

Bad areas on the disk, other hardware failures, or software errors can damage the file system and cause problems with the file and cannot be deleted. Typical operations may fail in different ways. When a file system corruption is detected, you will usually receive a message prompting Chkdsk to run.

If this is the case, you can run the Chkdsk utility on the disk volume to correct any errors. Depending on the nature of the damage, Chkdsk may be able to recover the file data and may not be able to recover, but Chkdsk can return the file system to an internally consistent state. Commands and parameters for the Chkdsk utility can be viewed at the command prompt “Chkdsk/?”.

Reason three: The file uses an access control list

If a file uses an Access Control List (ACL) and the operator does not have the appropriate permissions, then When you delete a file, you may see a "Access denied" prompt.

Typically, administrators have the implicit ability to take ownership of any file, and file owners have the implicit ability to modify file permissions. However, these default permissions can be modified.

To resolve the problem that files cannot be deleted due to ACLs, you must log in as a user with appropriate privileges, or give yourself permission to delete files before you can delete files. It is important to note that the operator must have ownership of these files in order 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 modifying it with the command line tool Cacls.exe.



Four reasons: The file name using a reserved name

As we all know, such as AUX, LPT1 such as legacy DOS device name is reserved. For backward compatibility, these file names are not allowed in Windows, nor can they be created using typical Win32 file calls. Conversely, if the file name is a reserved name in the Win32 namespace, it may not be possible to delete the file.

To solve 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 a path to the file with a specific syntax, you can also bypass the typical Win32 reserved name check with some built-in commands. For example, using the following command in Windows XP, you can delete the file named "ldt;lpt1" (Del command followed by “?” to avoid the validity of Windows check file name): Del c:[/URL] file path Lpt1.

Cause five: Invalid file name

If the file name includes an invalid name, such as a trailing space, or a trailing period, or the file name consists of only one space, It is also possible that the file cannot be deleted. It is worth mentioning that if you use a typical Win32 syntax to open a file with trailing or trailing periods in its name, trailing spaces or periods will be removed before the actual file is opened. Therefore, if there are two files named "ldquo;File.txt" and "File.txt" in the same folder (note the spaces after the second file name), open the second when using standard Win32 calls. When the files are actually opened, the first file is actually opened. Similarly, if the name of the file is only “" (a space character), when you try to open it with a standard Win32 call, the file's parent folder is actually opened. In this case, if you try to change the security settings on these files, you may accidentally change the settings on other files.

Similar to resolving filenames 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 of trailing spaces)

Cause six: File path is too deep to access

File is located The path with a deeper path character number (MAX_PATH) may cause the file to be inaccessible. Of course, this situation is rare. If the path is deep because the folder name is too long, the easiest solution is to access the file using the automatically generated 8.3 name. 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 target file does not exceed MAX_PATH. If the file is deeper than 128 folders, you can access the file by creating a network share that is as deep as possible in the folder tree and then accessing the share.

In general, if you encounter a situation where the file path is too deep to be accessible, you can manage these files by using the software that created the file. That is, if there is a program that can create files that exceed MAX_PATH, we can also use the program to manage these files. In addition, deep-structured files created through network sharing can also be deleted by using the same share.

I have previously described several reasons why files or folders cannot be deleted in Windows systems and how to solve them. In some cases, different combinations of the above various reasons may also be encountered, making the process of deleting files more complicated. This requires the reader to be able to use the various utilities provided by Microsoft to solve the problem.

Copyright © Windows knowledge All Rights Reserved