|
whiteyoo
新手上路

积分 16
发帖 11
注册 2006-10-21
状态 离线
|
『楼 主』:
[求助]寻求参数解释:DEL /F /A /Q \\?\%1和RD /S /Q \\?\%1
使用 LLM 解释/回答一下
前段时间看到这样一段代码:
DEL /F /A /Q \\?\%1
RD /S /Q \\?\%1
前面的能看懂,只是对后面的\\?\%1不明白,似乎%1是默认为使用此批处理时输入的第一个值,请教大家能给个详细的解释,//?是什么?路径?
谢谢!
───────────────── 版务记录 ─────────────────
执行:HAT
操作:在帖子标题中增加搜索关键字;代码加code标签
说明:原标题"寻求一段代码里参数的解释"不利于论坛搜索
处罚:扣除2点积分
提示:建议阅读以下帖子
{1415}提问的智慧
{7326}论坛新手必读,所有人的基本行为准则
{22703}请不要做浮躁的人
{32667}那些连标题都写不清楚的人们啊,你们醒醒吧
{32825}本版严厉整顿烂帖
───────────────── 版务记录 ─────────────────
Last edited by HAT on 2008-11-13 at 13:56 ]
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 ]
此帖被 -2 点积分 点击查看详情 评分人:【 HAT 】 | 分数: -2 | 时间:2008-11-13 13:57 |
|
|
|
2008-11-13 11:03 |
|
|
5872169
高级用户
   
积分 959
发帖 474
注册 2007-10-25
状态 离线
|
|
2008-11-13 13:21 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
Q: 为什么rd /s /q \\.\h:\autorun.inf\这条命令为什么能删除包含畸形文件夹在内的所有文件夹?
\\.\理解为\\127.0.0.1\就行了,当然实际上是行不通的。
UNC的一个本地化特例。
?\可以理解成遍历,?是统配符,表示匹配0个或1个任意字符。
.\代表本地节点,在概念上来有点像磁盘根目录,也可以说成是计算机根目录。
所以dir \\.\C:\是可以被命令行解释器识别的,更可以跨盘符的来使用绝对路径引用,例如:
F:\>\\.\C:\windows\system32\cmd.exe
Microsoft Windows XP
(C) 版权所有 1985-2001 Microsoft Corp.
F:\>
使用UNC路径不会捡测路径中的保留字设备名称等,因此删除包含畸形文件夹在内的所有文件夹?。
Q: 为什么del /q /f /a \\?\%1可以删除所有文件?
A: UNC路径的一个特例。UNC路径就是符合 \\servername\sharename 格式,其中 servername 是服务器名,sharename 是共享资源的名称。?是统配符,表示匹配0个或1个任意字符。使用UNC路径不会捡测路径中的保留字设备名称等,因此可以用这种方法来删除特殊文件或目录。
Q: 为什么说这样的命令非常危险?
A: 如果你想删除的文件夹中包含特殊路径,可能导致整个磁盘分区的数据全部被删除。因此,如果你还不能对这个命令了如指掌,不建议使用这样的命令。
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.
|

 |
|
2008-11-13 13:24 |
|
|
purplelichen
新手上路

积分 8
发帖 8
注册 2008-11-10
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
Q: 为什么说这样的命令非常危险?
A: 如果你想删除的文件夹中包含特殊路径,可能导致整个磁盘分区的数据全部被删除。因此,如果你还不能对这个命令了如指掌,不建议使用这样的命令。
----------------------------
我想强调以上这句话,举一例:
假设h:盘是一个u盘分区,下面有一个 删除顽固文件.bat,代码为:
rem ---------------------------------------------
DEL /F /A /Q \\?\%1
RD /S /Q \\?\%1
rem ---------------------------------------------
同时h:盘下还有一个取名为 &1.txt 的文本文件,此时
你想用 删除顽固文件.bat 删除 &1.txt,当你把 &1.txt 拖到
删除顽固文件.bat 上后,发现h:盘下所有的文件和文件夹全
被删除了。
这是因为传递的参数中含有特殊字符"&"(这样的特殊字符还有"^"),
对这个问题感兴趣或者有解决方案的高手可以去本版的这个主题:
关于批处理可替换参数的问题
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
|
|
2008-11-17 21:58 |
|
|
radem
高级用户
    CMD感染者
积分 691
发帖 383
注册 2008-5-23
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
真是非常危险,大家要慎重使用这样的命令
It's really very dangerous. Everyone should use such commands with caution.
|

 |
|
2008-11-19 12:17 |
|
|
ZJHJ
高级用户
   
积分 609
发帖 374
注册 2006-8-2
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by purplelichen at 2008-11-17 21:58:
Q: 为什么说这样的命令非常危险?
A: 如果你想删除的文件夹中包含特殊路径,可能导致整个磁盘分区的数据全部被删除。因此,如果你还不能对这个 ...
经我实验不是带^字符和带&字符的会带来危险,而是有带^&组合字符的一定有危险.
不过以下代码不会带来危险:
@echo off
if not "%~n1"=="" if not exist "%~f1" goto AAS
if not "%~n1"=="" if exist "%~f1" goto AAS
color 7c
cls
@echo.
@echo 文件垃圾桶
@echo.
@echo 可删除任意文件或畸形目录,可将目标文件或目录拖放垃圾桶中.
@echo.
@echo 为了用户文件安全,对带有"^&"组合字符文件名的危险删除进行避免.
@echo.
@echo 制作: 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 为了安全,不支持此类危险删除。
echo
pause>nul 2>nul
Last edited by ZJHJ on 2008-11-20 at 22:10 ]
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 ]
|
|
2008-11-20 22:05 |
|
|
menghen
新手上路

积分 10
发帖 6
注册 2007-12-14
状态 离线
|
|
2009-1-27 00:00 |
|
|
samliu
新手上路

积分 15
发帖 15
注册 2009-1-24
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
学习了 还好没有在U盘中试过
要不可就真的危险了
谢谢 楼主的提醒
Learned. Fortunately, I haven't tried it on the USB drive. Otherwise, it would really be dangerous. Thanks, the landlord's reminder
|
|
2009-2-5 22:14 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
这不是因为这个UNC标识而导致的危险,是批处理自身造成的错误
你在批处理中传递H:\&1.txt
那么执行的就是
rd /s /q \\?\H:\
1.txt
del /f /a /q \\?\H:\
1.txt
&在cmd是一个特珠的连接命令
你执行rd /s /q H:\&1.txt的结果也是一样的
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 |
|
2009-2-6 17:20 |
|
|
zhengqian529
初级用户
 
积分 100
发帖 93
注册 2009-1-14 来自 湖南
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
受教了
为什么一直以来的标准不限制文件名里面可以包含'&'字符,而只是限制 ‘/ \ : * ? " < > |’
Got it, learned something. Why has the standard not restricted the inclusion of the '&' character in file names all along, but only restricted '/ \ : * ? " < > |'?
|
|
2009-2-6 19:24 |
|