|
kmlxk
初级用户
 
积分 45
发帖 17
注册 2006-9-23
状态 离线
|
『楼 主』:
怎么用for命令删除各个分区中的autorun.inf
使用 LLM 解释/回答一下
有多个分区C..D..E.....J,怎么使用批处理文件实现删除各个分区中的autorun.inf(带有隐藏属性)
for(....?...) (attrib -s -h -r autorun.inf
del autorun.inf)
To delete autorun.inf with hidden attributes in each partition C..D..E.....J using a batch file, you can use a loop like this:
```batch
@echo off
for %%i in (C D E F G H I J) do (
if exist %%i:\autorun.inf (
attrib -s -h -r %%i:\autorun.inf
del /f /q %%i:\autorun.inf
)
)
```
This batch file loops through each drive from C to J, checks if autorun.inf exists on that drive, removes the hidden, system, and read-only attributes, and then deletes the file.
|
|
2006-9-24 04:53 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
原理:
1、for枚举所有盘符
2、删指定的文件
* 有什么命令带有方便删除那些具有只读或隐藏等属性的文件呢?
可以通过 dir /a 的参数来列出隐藏的文件,方便寻找和试验~:)
DEL命令(windows下的dos环境)可以帮助删除,可以不用Attrib了。
DEL命令的使用帮助:
=============================================================
D:\>del /?
删除一个或数个文件。
DEL attributes]] names
ERASE attributes]] names
names 指定一个或数个文件或目录列表。通配符可被用来
删除多个文件。如果指定了一个目录,目录中的所
有文件都会被删除。
/P 删除每一个文件之前提示确认。
/F 强制删除只读文件。
/S 从所有子目录删除指定文件。
/Q 安静模式。删除全局通配符时,不要求确认。
/A 根据属性选择要删除的文件。
attributes R 只读文件 S 系统文件
H 隐藏文件 A 存档文件
- 表示“否”的前缀
如果命令扩展被启用,DEL 和 ERASE 更改如下:
/S 开关的显示句法会颠倒,即只显示已经
删除的文件,而不显示找不到的文件。
=============================================================
非常危险的删除一个盘下所有目录中的所有你指定的文件!
===============
D:\>del /p /f /s /a d:*.bak
===============
Del 后面加了/P这个参数,这是在试验自己写的批处理是否正确而让删除前都提示
这句在试验时是必须的!
///// 下面命令危险,操作不好数据全没 ///////
刚才在试验的时候键错了命令:
(del d:这里就错了,是习惯造成的,所以后面的*.bak它是不管的)
====================
D:\>del d: /f /s /q /p *.bak
D:\hosts,要删除(Y/N)吗? n
D:\Windows Server 2003 For Intel.GHO,要删除(Y/N)吗? n
D:\# 29号机试准备\# 考试专用目录.rar,要删除(Y/N)吗? n
D:\# 29号机试准备\j2ee.rar,要删除(Y/N)吗?
====================
幸好习惯了用“提示”来做实验,和没有选择“/Q”的安静模式,因为安静模式的参数是不经你确认,当你还不及后悔的时候所有东西就全被删光了!
在试验其它for的时候最好用ECHO代替实际要干的事情。
幸好我这17个G的数据,多检查要出现的万一,哈哈……
正确的命令操作:
////////////// 注意: 操作不当,同样危险 ///////
====================================
del /f /s /a /q d:*.bak
====================================
上面的指令就是删除指定D:盘上所有目录与子目录中所有加了任何属性的 *.BAK 文件!并且不经过人工确认直接就删!
所以,请不要使用*.* 之后的危险操作。
如果换成楼主要的就是:
====================================
del /f /s /a /q d:autorun.inf
====================================
可以通过for枚举所有盘符来达到自动删除所有盘上指定文件。
Principle:
1. Enumerate all drive letters using for
2. Delete specified files
* Is there any command that is convenient for deleting files with read-only or hidden attributes?
You can list hidden files by using the /a parameter of dir, which is convenient for finding and testing~ : )
The DEL command (in the DOS environment under Windows) can help with deletion, and you don't need to use Attrib.
DEL command usage help:
=============================================================
D:\>del /?
Deletes one or more files.
DEL attributes]] names
ERASE attributes]] names
names Specifies one or more files or directory lists. Wildcards can be used
to delete multiple files. If a directory is specified, all files in the
directory will be deleted.
/P Prompts for confirmation before deleting each file.
/F Forces deletion of read-only files.
/S Deletes specified files from all subdirectories.
/Q Quiet mode. Does not require confirmation when deleting global wildcards.
/A Selects files to delete based on attributes.
attributes R Read-only files S System files
H Hidden files A Archive files
- Prefix indicating "no"
If command extensions are enabled, DEL and ERASE change as follows:
The display syntax of the /S switch is reversed, that is, only the deleted files are displayed, and the files not found are not displayed.
=============================================================
Deleting all files in all directories on a drive specified by you is extremely dangerous!
===============
D:\>del /p /f /s /a d:*.bak
===============
The /P parameter is added after Del. This is to prompt before deletion when testing whether your self-written batch processing is correct.
This sentence is necessary during testing!
///////////// The following commands are dangerous, and improper operation will result in all data being lost ///////////////
I made a typo in the command during testing:
(Del d: is wrong here, it's a habit, so the *.bak behind it is ignored)
====================
D:\>del d: /f /s /q /p *.bak
D:\hosts, do you want to delete (Y/N)? n
D:\Windows Server 2003 For Intel.GHO, do you want to delete (Y/N)? n
D:\# 29 Machine Test Preparation\# Exam Special Directory.rar, do you want to delete (Y/N)? n
D:\# 29 Machine Test Preparation\j2ee.rar, do you want to delete (Y/N)?
====================
Fortunately, I got used to using "prompt" for testing and did not choose the quiet mode of the /Q parameter, because the quiet mode parameter does not require your confirmation, and all things will be deleted before you can regret it!
When testing other fors, it is best to use ECHO instead of actually doing the things.
Fortunately, I have 17GB of data. Check more for possible accidents, haha...
Correct command operation:
///////////////////////// Note: Improper operation is also dangerous ///////////////////////
====================================
del /f /s /a /q d:*.bak
====================================
The above instruction is to delete all *.BAK files with any attributes in all directories and subdirectories on drive D: and delete them directly without manual confirmation!
Therefore, please do not use dangerous operations like *.* later.
If it is what you want:
====================================
del /f /s /a /q d:autorun.inf
====================================
You can enumerate all drive letters through for to automatically delete specified files on all drives.
|
|
2006-9-24 05:32 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
做的一个实验,用echo避免出现意想不到的情况:)
C:\TEMP>copy con test.bat
@ECHO off
FOR %%c in (Z,Y,X,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C) do (
IF exist %%c: (
echo del /f /s /a /q %%c:*.bak
)
)
^Z
已复制 1 个文件。
C:\TEMP>test.bat
del /f /s /a /q G:*.bak
del /f /s /a /q F:*.bak
del /f /s /a /q E:*.bak
del /f /s /a /q D:*.bak
del /f /s /a /q C:*.bak
C:\TEMP>
An experiment done, using echo to avoid unexpected situations :)
C:\TEMP>copy con test.bat
@ECHO off
FOR %%c in (Z,Y,X,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C) do (
IF exist %%c: (
echo del /f /s /a /q %%c:*.bak
)
)
^Z
1 file(s) copied.
C:\TEMP>test.bat
del /f /s /a /q G:*.bak
del /f /s /a /q F:*.bak
del /f /s /a /q E:*.bak
del /f /s /a /q D:*.bak
del /f /s /a /q C:*.bak
C:\TEMP>
|
|
2006-9-24 05:34 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
这是楼主要的自动删除所有盘上的任何目录下的具有任何属性的所有autorun.inf文件:
@ECHO off
FOR %%c in (Z,Y,X,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C) do (
IF exist %%c: (
del /f /s /a /q %%c:autorun.inf
)
)
Last edited by redtek on 2006-9-24 at 05:37 ]
This is the code that the original poster wants to automatically delete all autorun.inf files with any attributes in any directory on all disks:
@ECHO off
FOR %%c in (Z,Y,X,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C) do (
IF exist %%c: (
del /f /s /a /q %%c:autorun.inf
)
)
Last edited by redtek on 2006-9-24 at 05:37 ]
|
|
2006-9-24 05:36 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
|
2006-9-24 06:59 |
|
|
kmlxk
初级用户
 
积分 45
发帖 17
注册 2006-9-23
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
呵呵,不好意思哈,一时心切就问了,没往后面翻看~
Hehe, sorry about that. I was eager and asked without looking further back.
|
|
2006-9-24 07:26 |
|
|
SunRiseBoy
初级用户
 
积分 38
发帖 20
注册 2006-7-4
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
如果只删除磁盘根目录下的指定文件,For怎么改,不删除子目录的INF(太菜了4楼的没有看懂运行了一下把我的不在根目录下的驱动备份中的autorun.inf删除了)。
If you only want to delete the specified files in the root directory of the disk, how to modify the For? Do not delete the INF in the subdirectories. (Too stupid, I didn't understand the 4th floor. I ran it and deleted the autorun.inf in my driver backup that was not in the root directory.)
|
|
2007-6-29 02:15 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by SunRiseBoy at 2007-6-29 02:15:
如果只删除磁盘根目录下的指定文件,For怎么改,不删除子目录的INF(太菜了4楼的没有看懂运行了一下把我的不在根目录下的驱动备份中的autorun.inf删除了)。
@echo off
rem 指定的文件 file
set file=a.txt
for %%a in ( c d e f g h i j k l ) do (
if exist %%a:\%file% del %%a:\%file%
)
Originally posted by SunRiseBoy at 2007-6-29 02:15:
If you only delete the specified file in the root directory of the disk, how to change the For, without deleting the INF in the subdirectory (too stupid, I didn't understand the 4th floor, I ran it and deleted the autorun.inf in my driver backup not in the root directory).
@echo off
rem Specified file file
set file=a.txt
for %%a in ( c d e f g h i j k l ) do (
if exist %%a:\%file% del %%a:\%file%
)
|
|
2007-6-29 02:44 |
|
|