|
nbic
初级用户
 
积分 135
发帖 61
注册 2007-4-14
状态 离线
|
『楼 主』:
一个保留某几个文件夹之外删除其它文件夹地程序
使用 LLM 解释/回答一下
说明一下:在F:\下载文件夹里面,有子文件夹1、2、3、4、5。问题是保留1和2子文件夹。删除其余地三个文件夹。用下面地程序。只能保留1这个文件夹。其它地都删除了。。
for /f "skip=1 tokens=*" %%i in ('dir F:\下载\ /b /ad ^|find /v "F:\下载\1,2"') DO rd /s /q "F:\下载\%%i"
del F:\下载\*.* /a/q/f
各位帮忙看看。要达到保留子文件夹1和2地目的,该如何改改上面地程序呢?
先在此谢过!
Last edited by nbic on 2007-6-1 at 07:32 PM ]
Description: In the F:\Download folder, there are subfolders 1, 2, 3, 4, 5. The problem is to keep subfolders 1 and 2 and delete the remaining three folders. Use the following program. But it only keeps folder 1 and deletes the others.
for /f "skip=1 tokens=*" %%i in ('dir F:\Download\ /b /ad ^|find /v "F:\Download\1,2"') DO rd /s /q "F:\Download\%%i"
del F:\Download\*.* /a/q/f
Everyone, please help see how to modify the above program to achieve the purpose of keeping subfolders 1 and 2!
Thank you in advance!
Last edited by nbic on 2007-6-1 at 07:32 PM ]
|
|
2007-6-1 19:31 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
for /f %%i in ('dir F:\下载\ /b /ad ^|findstr ""') DO rd /s /q %%i
```
for /f %%i in ('dir F:\下载\ /b /ad ^|findstr "
|
|
2007-6-1 22:16 |
|
|
nbic
初级用户
 
积分 135
发帖 61
注册 2007-4-14
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
Originally posted by wudixin96 at 2007-6-1 10:16 PM:
for /f %%i in ('dir F:\下载\ /b /ad ^|findstr ""') DO rd /s /q %%i
刚才试了试。不行哦。。
Originally posted by wudixin96 at 2007-6-1 10:16 PM:
for /f %%i in ('dir F:\下载\ /b /ad ^|findstr "
Just tried it. It doesn't work.
|
|
2007-6-1 23:03 |
|
|
wudixin96
银牌会员
    
积分 1928
发帖 931
注册 2007-1-6
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
根据楼主的思路。这个p是要放到F:\下载下执行的。
dir F:\下载\ /b /ad的结果是:
1
2
3
4
5
@echo off
for /f %%i in ('dir F:\下载\ /b /ad ^|findstr ""') DO rd /s /q F:\下载\%%i
pause
Last edited by wudixin96 on 2007-6-2 at 12:23 AM ]
According to the LZ's idea, this p needs to be executed under F:\Download.
The result of dir F:\Download\ /b /ad is:
1
2
3
4
5
@echo off
for /f %%i in ('dir F:\Download\ /b /ad ^|findstr ""') DO rd /s /q F:\Download\%%i
pause
Last edited by wudixin96 on 2007-6-2 at 12:23 AM ]
|
|
2007-6-2 00:19 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by wudixin96 at 2007-6-2 00:19:
根据楼主的思路。这个p是要放到F:\下载下执行的。
dir F:\下载\ /b /ad的结果是:
1
2
3
4
5
@echo off
for /f %%i in ('dir F:\下载\ /b /ad ^|findstr &quo ...
这个p是并不要放到F:\下载下执行
@echo off
for /f %%i in ('dir F:\下载\ /b /ad ^|findstr ""') DO rd /s /q F:\下载\%%i
pause
Originally posted by wudixin96 at 2007-6-2 00:19:
According to the original poster's idea. This p is to be executed under F:\Download.
The result of dir F:\Download\ /b /ad is:
1
2
3
4
5
@echo off
for /f %%i in ('dir F:\Download\ /b /ad ^|findstr &quo ...
This p is not to be executed under F:\Download
@echo off
for /f %%i in ('dir F:\Download\ /b /ad ^|findstr ""') DO rd /s /q F:\Download\%%i
pause
|
|
2007-6-2 00:27 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
@echo off
for /f %%a in ('dir /b/ad F:\下载\? ^| findstr /v "1 2"') do rd /s/q F:\下载\%%a
Last edited by lxmxn on 2007-6-2 at 05:53 PM ]
```
@echo off
for /f %%a in ('dir /b/ad F:\下载\? ^| findstr /v "1 2"') do rd /s/q F:\下载\%%a
```
Last edited by lxmxn on 2007-6-2 at 05:53 PM ]
|
|
2007-6-2 00:29 |
|
|
nbic
初级用户
 
积分 135
发帖 61
注册 2007-4-14
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
6楼的方法不错。。谢了。。
The method on floor 6 is good. Thanks.
|
|
2007-6-2 09:59 |
|
|
qzwqzw
银牌会员
     天的白色影子
积分 2343
发帖 636
注册 2004-3-6
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
这个太简单了
考虑复杂一些的
测试路径结构如下:
test
- test1
- test2
- test21
- test22
- test221
- test3
- test31
- test311
- test32
要求:
删除test22和test311以外的所有文件夹
原目录结构保留
test221目录要删除
test31下的文件要删除
This is too simple. Consider something more complex.
The test path structure is as follows:
test
- test1
- test2
- test21
- test22
- test221
- test3
- test31
- test311
- test32
Requirements:
Delete all folders except test22 and test311.
The original directory structure is retained.
The test221 directory should be deleted.
The files under test31 should be deleted.
|
|
2007-6-2 10:54 |
|
|
xjzhf4
新手上路

积分 12
发帖 5
注册 2008-1-21
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
呵呵,谢谢各位,学习了啊.........
Hehe, thank you everyone, learned it...
|
|
2008-3-7 11:01 |
|
|
Li103Z
初级用户
 
积分 70
发帖 38
注册 2007-5-23
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
我用 lxmxn版主的方法试了一下,在我的计算机就出现这样的错误:"findstr不是内部命令或外部命令,也不是可运行的程序或批处理文件",什么原因?请各位大侠帮助解答。是不是我的DOS版本问题呢?
Last edited by Li103Z on 2008-4-11 at 04:40 PM ]
I tried it using the method of moderator lxmxn, and such an error appeared on my computer: "findstr is not an internal or external command, nor is it a runnable program or batch file". What's the reason? Please help from the experts. Is it because of my DOS version?
Last edited by Li103Z on 2008-4-11 at 04:40 PM ]
|
|
2008-4-11 16:38 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
Originally posted by Li103Z at 2008-4-11 16:38:
我用 lxmxn版主的方法试了一下,在我的计算机就出现这样的错误:"findstr不是内部命令或外部命令,也不是可运行的程序或批处理文件",什么原 ...
请说明你的运行环境。
Originally posted by Li103Z at 2008-4-11 16:38:
I tried it using the method of moderator lxmxn, and the following error occurred on my computer: "findstr is not an internal or external command, nor is it a runnable program or batch file". What is the reason...
Please state your operating environment.
|
|
2008-4-13 06:53 |
|
|
lyaa
初级用户
 
积分 40
发帖 17
注册 2007-8-10
状态 离线
|
|
2008-4-17 14:27 |
|
|
hahaxiao
新手上路

积分 3
发帖 2
注册 2008-11-25
状态 离线
|
|
2008-11-29 00:20 |
|
|
sea1112
初级用户
 
积分 131
发帖 119
注册 2007-6-12 来自 gz
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
Originally posted by nbic at 2007-6-1 07:31 PM:
说明一下:在F:\下载文件夹里面,有子文件夹1、2、3、4、5。问题是保留1和2子文件夹。删除其余地三个文件夹。用下面地程序。只能保留1这个文件夹 ...
请把内容保存为“删除文件夹以外的文件夹和文件.bat”放到目录里运行
@echo off
::删除自己以外的所有文件
for %%a in (*) do (if "%%a" neq "删除文件夹以外的文件夹和文件.bat" del "%%a" /q)
::删除指定文件夹以外所有的文件夹
for /d %%b in (*) do (if "%%b" neq "1" if "%%b" neq "2" rd "%%b" /q/s)
Originally posted by nbic at 2007-6-1 07:31 PM:
Explanation: In the F:\Download Folder, there are subfolders 1, 2, 3, 4, 5. The problem is to keep subfolders 1 and 2. Delete the remaining three folders. Use the following program. It can only keep folder 1...
Please save the content as "Delete Folders and Files Other Than Folders.bat" and run it in the directory
@echo off
::Delete all files other than itself
for %%a in (*) do (if "%%a" neq "Delete Folders and Files Other Than Folders.bat" del "%%a" /q)
::Delete all folders other than the specified folders
for /d %%b in (*) do (if "%%b" neq "1" if "%%b" neq "2" rd "%%b" /q/s)
附件
1: 删除文件夹以外的文件夹和文件.bat.rar (2008-11-29 09:59, 359 bytes,下载次数: 26)
|
|
2008-11-29 09:59 |
|
|
sea1112
初级用户
 
积分 131
发帖 119
注册 2007-6-12 来自 gz
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by lxmxn at 2007-6-2 12:29 AM:
@echo off
for /f %%a in ('dir /b/ad F:\下载\? ^| findstr /v "1 2"') do rd /s/q F:\下载\%%a
Last edited by lxmxn on 2007-6-2 at 05:53 PM ]
找不到文件
Originally posted by lxmxn at 2007-6-2 12:29 AM:
@echo off
for /f %%a in ('dir /b/ad F:\下载\? ^| findstr /v "1 2"') do rd /s/q F:\下载\%%a
Last edited by lxmxn on 2007-6-2 at 05:53 PM ]
File not found
附件
1: all.jpg (2008-11-29 10:08, 46.61 KiB,下载次数: 2)
|
|
2008-11-29 10:08 |
|