China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-11 08:39
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Seeking Parameter Explanation: DEL /F /A /Q \\?\%1 and RD /S /Q \\?\%1 View 3,520 Replies 9
Original Poster Posted 2008-11-13 11:03 ·  中国 陕西 榆林 电信
新手上路
Credits 16
Posts 11
Joined 2006-10-21 06:43
19-year member
UID 67463
Gender Male
Status Offline
A while ago I saw such a piece of code:
DEL /F /A /Q \\?\%1 
RD /S /Q \\?\%1

The previous part can be understood, but I don't understand the subsequent \\?\%1. It seems that %1 is the first value input when using this batch processing by default. Everyone, can you give a detailed explanation, what is //? For? Path?

Thank you!

───────────────── Moderation Record ─────────────────
Performed: HAT
Operation: Added search keywords in the post title; added code tags to the code
Explanation: The original title " Seeking explanation of parameters in a piece of code" is not conducive to forum search
Punishment: Deducted 2 points of points
Tip: It is recommended to read the following posts
{1415}The Wisdom of Asking Questions
{7326}Must-read for forum newcomers, basic code of conduct for everyone
{22703}Please don't be an impatient person
{32667} Those people who can't even write the title clearly, wake up
{32825}This version is strictly rectifying bad posts
───────────────── Moderation Record ─────────────────


[ Last edited by HAT on 2008-11-13 at 13:56 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
HAT -2 2008-11-13 13:57
Floor 2 Posted 2008-11-13 13:21 ·  中国 山东 济南 联通
高级用户
★★★
Credits 959
Posts 474
Joined 2007-10-25 10:40
18-year member
UID 100716
Gender Male
Status Offline
? is any path, any folder
Floor 3 Posted 2008-11-13 13:24 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Q: Why does the command `rd /s /q \\.\h:\autorun.inf\` can delete all folders including the malformed folders?

`\\.` can be understood as `\\127.0.0.1\`, but actually it doesn't work.
A local special case of UNC.
`?\` can be understood as traversal, `?` is a wildcard, which means matching 0 or 1 arbitrary character.
`.\` represents the local node, conceptually a bit like the root directory of a disk, and can also be said to be the root directory of the computer.
So `dir \\.\C:\` can be recognized by the command line interpreter, and can also be used to reference absolute paths across drive letters. For example:
F:\>\\.\C:\windows\system32\cmd.exe
Microsoft Windows XP
(C) Copyright 1985-2001 Microsoft Corp.
F:\>
UNC paths do not detect reserved word device names in the path, so all folders including malformed folders can be deleted?

Q: Why can `del /q /f /a \\?\%1` delete all files?

A: A special case of UNC paths. UNC paths are in the format `\\servername\sharename`, where `servername` is the server name and `sharename` is the name of the shared resource. `?` is a wildcard, which means matching 0 or 1 arbitrary character. UNC paths do not detect reserved word device names in the path, so this method can be used to delete special files or directories.

Q: Why is such a command very dangerous?

A: If the folder you want to delete contains a special path, it may cause the data of the entire disk partition to be deleted. Therefore, if you are not fully familiar with this command, it is not recommended to use such a command.
Floor 4 Posted 2008-11-17 21:58 ·  中国 江苏 无锡 电信
新手上路
Credits 8
Posts 8
Joined 2008-11-10 20:58
17-year member
UID 130589
Gender Male
Status Offline
Q: Why is such a command very dangerous?

A: If the folder you want to delete contains special paths, it may cause the entire data of the disk partition to be deleted. Therefore, if you are not fully familiar with this command, it is not recommended to use such a command.


----------------------------
I want to emphasize the above sentence, take an example:

Suppose the h: drive is a USB flash drive partition, and there is a "Delete Stubborn Files.bat" below, the code is:

rem ---------------------------------------------
DEL /F /A /Q \\?\%1
RD /S /Q \\?\%1
rem ---------------------------------------------

At the same time, there is a text file named &1.txt under the h: drive. At this time
You want to use "Delete Stubborn Files.bat" to delete &1.txt. When you drag &1.txt to
On "Delete Stubborn Files.bat", you find that all files and folders under the h: drive are all
Was deleted.

This is because the passed parameter contains the special character "&" (such special characters also include "^"),
Those who are interested in this problem or have solutions can go to this topic in this section:

Regarding the problem of batch processing replaceable parameters
Floor 5 Posted 2008-11-19 12:17 ·  中国 广东 韶关 电信
高级用户
★★★
CMD感染者
Credits 691
Posts 383
Joined 2008-05-23 00:38
18-year member
UID 119451
Gender Male
Status Offline
It's really very dangerous. Everyone should use such commands with caution.
Floor 6 Posted 2008-11-20 22:05 ·  中国 四川 泸州 联通
高级用户
★★★
Credits 609
Posts 374
Joined 2006-08-02 22:38
20-year member
UID 59720
Status Offline
Originally posted by purplelichen at 2008-11-17 21:58:
Q: Why is such a command very dangerous?

A: If the folder you want to delete contains a special path, it may cause the data of the entire disk partition to be completely deleted. Therefore, if you still cannot ...


After my experiment, it's not that the ones with ^ characters and & characters are dangerous, but those with ^& combined characters are definitely dangerous.
However, the following code will not be dangerous:

@echo off
if not "%~n1"=="" if not exist "%~f1" goto AAS
if not "%~n1"=="" if exist "%~f1" goto AAS
color 7c
cls
@echo.
@echo File Trash Can
@echo.
@echo Can delete any file or abnormal directory, can drag and drop the target file or directory into the trash can.
@echo.
@echo To ensure user file safety, avoid dangerous deletion of file names with "^&" combined characters.
@echo.
@echo Made by: QQ: 251485609
@echo.
pause>nul 2>nul
echo 
goto eof

:AAS
set rt="%~n1"
if "%rt:~1,1%"=="&" goto BS
if "%rt:~1,2%"=="^&" goto BS
del /f /a /q \\?\%1 >nul 2>nul
rd /s /q \\?\%1 >nul 2>nul
echo 
goto eof

:BS
@echo.
@echo For safety, such dangerous deletion is not supported.
echo 
pause>nul 2>nul


[ Last edited by ZJHJ on 2008-11-20 at 22:10 ]
Floor 7 Posted 2009-01-27 00:00 ·  中国 山东 济南 电信
新手上路
Credits 10
Posts 6
Joined 2007-12-14 15:29
18-year member
UID 105649
Gender Male
Status Offline
Floor 8 Posted 2009-02-05 22:14 ·  中国 黑龙江 哈尔滨 电信
新手上路
Credits 15
Posts 15
Joined 2009-01-24 10:46
17-year member
UID 137352
Gender Male
Status Offline
Learned. Fortunately, I haven't tried it on the USB drive. Otherwise, it would really be dangerous. Thanks, the landlord's reminder
Floor 9 Posted 2009-02-06 17:20 ·  中国 广东 广州 番禺区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
This is not a danger caused by this UNC identifier, but an error caused by the batch processing itself. You pass H:\&1.txt in the batch processing, then what is executed is
rd /s /q \\?\H:\
1.txt
del /f /a /q \\?\H:\
1.txt
& is a special connection command in cmd. The result of you executing rd /s /q H:\&1.txt is also the same
49206C6F766520796F752067757973 54656C3A3133383238343036373837
Floor 10 Posted 2009-02-06 19:24 ·  美国 华盛顿州 金 雷德蒙德 Microsoft
初级用户
★★
Credits 100
Posts 93
Joined 2009-01-14 15:04
17-year member
UID 136661
Gender Male
From 湖南
Status Offline
Got it, learned something. Why has the standard not restricted the inclusion of the '&' character in file names all along, but only restricted '/ \ : * ? " < > |'?
Forum Jump: