1. The original content of force_delete.bat is as follows:
Force_detele.bat
-----------------------------
@ Echo off; this command can be omitted to hide screen output.
@ Del/f/A/Q \\? \ % 1
@ RD/S/Q \\? \ % 1
-----------------------------
Then, if nothing is displayed, the file or folder tree will be deleted...
2. Why?
Del File Deletion command/F is to force the deletion of read-only attribute files/A without attribute parameters (/A: XX) can ignore other attributes except read-only attributes (such as system attributes) /Q is automatically skipped for confirmation
The RD command to delete folders and folders tree/s indicates to delete the folder tree. (If a folder has a file or a subfolder does not add this parameter, the system prompts that the folder is not empty and cannot be deleted ..) /Q is also automatically skipped for confirmation
3. The point is "\\? What does \ % 1 mean?
When we drag the file (eg. test.txt full path: "D: \ test.txt") to the BAT file icon, what will happen?
In fact, this is equivalent to the execution (assuming the BAT file path is D: \ GD. BAT ):
"D: \ GD. Bat" D: \ test.txt ""
In this case, "d: \ test.txt" is the first invocation command line parameter of GD. bat, and % 1 is the variable representing this string of characters.
Therefore, the actual execution is as follows:
-----------------------------------
> @ Echo off [! Enter!]
> @ Del/f/A/Q \\? \ "D: \ test.txt "[! Enter!]
> @ RD/S/Q \\? \ "D: \ test.txt "[! Enter!]
The system cannot find the specified file.
----------------------------------
Of course, del has killed the file at this time, and RD certainly cannot be found. Both commands are used to adapt to various situations.
4. Why not use "\" instead of the full path "\\? \ "+ Full path?
This is an application of a special protocol. This special protocol is unc -- Universal Naming Convention. The Chinese language is "general naming Rules". For details, refer to Baidu encyclopedia...
Simply put, \ hostname \ resouce_or_patHSuch a path can be understood as the full name of the resource in WINNT and later systems based on its technology. In addition, the complete UNC format must be prefixed with "file:". However, in different environments, it can be removed and sometimes saved ..
5. In this example "\\? \ "+ The complete disk path name is a special UNC localization instance, because in Unc? Is a wildcard representing 1 or 0 characters, so the actual command is not? But. (too small .. English periods)
What is this? Simply put, it is a local reference, local computer root (and point the root directory )... But is it localhost or the return address 127.0.0.1?
Answer: No! To put it simply, they are network roots (please allow me to be so superficial in self-creation ...), So? If you replace it with localhost or 127.0.0.1, the command is invalid.
Continue to the root of the local computer .. This is equivalent to the "my computer" layer, followed by the path containing the drive letter.
Bytes ------------------------------------------------------------------------------------
6. Well, what about UNC absolute path?
Here is a special attribute of the UNC absolute path, which seems to have continued since the WINNT era ..
That is, when you use a UNC absolute path to locate a file or folder, the system ignores the reserved words, device names, and file system control file names protected by special characters.
Therefore, you can use this technique to delete files or folders that cannot be deleted (except for running files or referenced files that do not have the corresponding permission to delete or change permissions. [This is unknown, NTFS is so powerful?] Dedicated Technical Protection)
7. Finally... Well, make a warning or caution...
Yes ..Exercise caution
(Thank you.Purplelichen and moderator hat @Www.cn-dos.netExample provided by Forum)
Potential danger of accidental deletion when the file name contains some special characters!
Set H: it is a USB flash drive, and there is a fdel. bat below:
Del/f/A/Q \\? \ % 1
RD/S/Q \\? \ % 1
H: there is also a text file named &1.txt.
You want to use fdel. BAT to delete &1.txt. When you drag &1.txt
After fdel. bat, all files and folders under H: will no longer exist...
This is exactly the role of the special character "&" (also: "^ &" has a similar effect) (when executed, it becomes RD/S/Q \\? \ "H :\& 1.txt", & will be parallel before and after, so h: \ is cleared, then 1.txt is positioned for deletion...
8. In summary: this bat is very powerful and concise, but it must not be used to delete files or folders in the file name (especially the first character of the file name is & or ^, otherwise, it may be deleted by mistake.
9. Appendix:
relatively secure Code , it mainly includes the determination of file names: zjhj @ WWW .cn-dos.net Forum is provided. You have modified the settings. Thank you ~~ )
The following has not been verified, please be careful when using ....
========================================================== ===
@ Echo off
If not "% ~ N1 "=" "if not exist" % ~ F1 "Goto CHK
If not "% ~ N1 "=" "If exist" % ~ F1 "Goto CHK
Color 7c
CLS
@ Echo
@ Echo stubborn file waste bin
@ Echo
@ ECHO: You can delete any stubborn file or directory, and drag and drop the target file or directory to the bat icon.
@ Echo
@ ECHO for user file security, dangerous deletion of file names with "&" and "^ &" Combination characters has been blocked
@ Echo
@ Echo Original Author Q #: 251485609
@ Pause> NUL 2> NUL
Echo on
Goto EOF
: CHK
Set RT = "% ~ N1"
If "% RT :~ 1, 1% "=" & "Goto fine
If "% RT :~ 1, 2% "=" ^ & "Goto fine
Del/f/A/Q \\? \ % 1> NUL 2> NUL
RD/S/Q \\? \ % 1> NUL 2> NUL
Echo on
Goto EOF
: Fine
@ echo
@ ECHO: Dangerous deletion is not supported for security purposes!
echo on
pause> NUL 2> NUL
==================== ======================