|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『楼 主』:
怎样用聪明的小DOS命令解决烦人问题?!(DOS高手小考题)
使用 LLM 解释/回答一下
你可能遇到过这样的情况:
你无意中把一批文件(假设全是文件,没有子目录)解压到了错误的目录(假设为C:\)下,后再把它们重新解压到正确的目录(D:\PROGRAM),你就需要删掉前面的那些文件嘛,但太多了,一个个的删太烦了..
那么怎样用一行DOS批处理解决问题呢?
另外,如果增加难度的话,这样:
假设你忘了原先把文件解压到了什么地方(错误的目录),(只知道是在C盘里),那该怎么写?
(这里要特别注意:要确定其他地方没有重要的同文件名的文件,或者为安全起见,把目录范围缩小到一个无用的文件夹内测试。。。比如,在C盘中建一个目录AB,再在AB中建CD目录,再把D:\PROGRAM中的文件复制进去,就以C:\AB\CD为测试范围...)
还有,如果被解压的文件中也有子目录怎么办?(一行肯定不行了)
You may have encountered such a situation:
You inadvertently extracted a batch of files (assuming all are files, no subdirectories) to the wrong directory (assuming C:\), and then extracted them again to the correct directory (D:\PROGRAM), you need to delete those previous files, but there are too many, and it's tedious to delete them one by one..
So how to solve it with a single line of DOS batch processing?
Also, if you increase the difficulty, like this:
Suppose you forgot where you originally extracted the files to (the wrong directory), (only knowing it's on the C drive), then how to write it?
(Here, it is especially necessary to make sure that there are no important files with the same file name elsewhere, or for safety, narrow the directory range to a useless folder for testing... For example, create a directory AB in C:\, then create a CD directory in AB, and then copy the files from D:\PROGRAM into it, and take C:\AB\CD as the test range...)
Also, what if the extracted files also have subdirectories? (One line is definitely not enough)
|
|
2004-11-6 00:00 |
|
|
doslr
初级用户
 
积分 168
发帖 27
注册 2004-11-3
状态 离线
|
  『第 2 楼』:
使用 LLM 解释/回答一下
win2000及以上的系统for /r %a in (*.*) do @echo %a >>err.txtfor /f %b in (err.txt) do @del %b
win2000 and above systems
for /r %a in (*.*) do @echo %a >>err.txt
for /f %b in (err.txt) do @del %b
|
|
2004-11-6 00:00 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
老兄啊! 你这样的话就删除全部文件了啊!不就等于 @del *.* /s 吗? (删除当前目录的全部文件)我狂晕!!..8u73yr7398231u
Dude! If you do that, you'll delete all files! Isn't that equivalent to @del *.* /s? (Delete all files in the current directory) I'm really dizzy!!..8u73yr7398231u
|
|
2004-11-7 00:00 |
|
|
死性不改
中级用户
  
积分 378
发帖 88
注册 2004-5-5
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
@echo offset /p drive=for /f %%i in ('dir *.* /b') do del %drive%:\%%i /q /s
@echo offset /p drive=for /f %%i in ('dir *.* /b') do del %drive%:\%%i /q /s
|

www.51ct.net |
|
2004-11-7 00:00 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
set /p drive= 好象是设DRIVE为当前目录,这个用处不大呀,你把当前目录改到你要的目录不就行了
set /p drive= It seems to set DRIVE as the current directory. This is not very useful. Can't you just change the current directory to the directory you want?
|
|
2004-11-7 00:00 |
|
|
死性不改
中级用户
  
积分 378
发帖 88
注册 2004-5-5
状态 离线
|
|
2004-11-7 00:00 |
|
|
死性不改
中级用户
  
积分 378
发帖 88
注册 2004-5-5
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
注意:98系统不能使用set /p来手动输入变量值。
chang.exe是第三方程序。
同时,必须存在因解压才产生的目录,如果解压时只释放出文件,没有产生新目录,请不要使用6楼的批处理。
Note: The Windows 98 system cannot use set /p to manually input variable values.
chang.exe is a third-party program.
Also, there must be a directory generated due to decompression. If only files are released during decompression and no new directory is generated, do not use the batch processing in floor 6.
|

www.51ct.net |
|
2004-11-7 00:00 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
题目的要求是1 不允许手动输入文件名(文件太多,太麻烦啊,烦人的事就是要批处理去做呀!)2 只要一行语句另外,好象DOS中没有CHANGE命令吧..
The requirement of the question is: 1. It is not allowed to manually enter the file name (there are too many files, it's too troublesome! The annoying thing is that it needs to be done with batch processing! ) 2. Just one line of statement. Also, it seems that there is no CHANGE command in DOS, right..
|
|
2004-11-7 00:00 |
|
|
死性不改
中级用户
  
积分 378
发帖 88
注册 2004-5-5
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
只需要输入其中一个文件名,因为只是通过这个文件找到错误解压目录。然后删除这个目录。chang.exe论坛中有。
Just input one of the file names, because it's only to find the wrong decompression directory through this file. Then delete this directory. chang.exe is in the forum.
|

www.51ct.net |
|
2004-11-7 00:00 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
|
2004-11-7 00:00 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
如果DOS能够满足你这种要求,DOS就不是DOS了,我想应该是神或者God!
If DOS could meet your such requirements, DOS wouldn't be DOS any more. I think it should be God or God!
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2004-11-8 00:00 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
CLIMBING啊, 大丈夫,一言既出,驷马难追哦,你可要为你的话负责哦。。DOS没你说的这么差哦..我说答案哦:(把目录切换到D:\PROGRAM), 这正是我自己遇到的情况.D:\PROGRAM>for %1 in (*) do del c:\%1如果不知道解压到了C盘的什么地方, 可加 /s,如下<img src="images/smilies/face-smile-big.png" align="absmiddle" border="0">:\PROGRAM>for %1 in (*) do del c:\%1 /s如果,解压的文件又有文件又有子目录,请再动动脑筋吧..
CLIMBING, it's okay, once a word is spoken, it's hard to take it back. You have to be responsible for your words. DOS isn't as bad as you said.. Let me say the answer: (Switch the directory to D:\PROGRAM), this is exactly the situation I encountered myself. D:\PROGRAM>for %1 in (*) do del c:\%1 If you don't know where it was extracted to on the C drive, you can add /s, like this: D:\PROGRAM>for %1 in (*) do del c:\%1 /s If the extracted files have both files and subdirectories, think harder..
|
|
2004-11-8 00:00 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
??? 这么到现在还没有人揭榜? (看来这个小题目不容易哦,..)那我说答案吧..(我研究了一个下午才解决哦!)又有子目录的话,就难上加难了,在2000XP,可以解决的,如下:切换到C,C:\for /r /d %1 in (*) do if %~n1==program rd %1 /s /q哈哈! 就这么简单!好了,在这个基础上,再增加一点难度吧,不过上面的问题中的解析目录名和他的路径后,一切就好办了..假设你有很多重复的目录(文件已经在上面的帖子中解决了)在c,d两个盘中,但你又不知道他们在哪里,怎样用一句批处理删掉d盘中的重复目录(假设属性都是可删的)要求:只用一句
??? No one has solved it yet? (It seems this little question is not easy..) Then I'll say the answer..(I spent an afternoon researching to solve it!) If there are subdirectories, it's even more difficult. In 2000XP, it can be solved as follows: Switch to C, C:\for /r /d %1 in (*) do if %~n1==program rd %1 /s /q Haha! It's that simple! Okay, let's add a little more difficulty on this basis. But after analyzing the directory name and its path in the above problem, everything is easy.. Suppose you have many duplicate directories (the files have been solved in the above post) in drives C and D, but you don't know where they are. How to use a single batch command to delete the duplicate directories in drive D (assuming all attributes are deletable) Requirement: Use only one sentence
|
|
2004-11-9 00:00 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
楼主有老王卖瓜的嫌疑噢。你自己首先就没有把问题交待清楚,让别人如何解决,而且你的解决方案中有很多漏洞,有可能删除完成后你的系统都启动不起来了,岂不晕死?除非你保证你的C盘就没有重要的东西(一般不会存在这种情况吧?)1、你必须保证你压缩文件中的文件在C盘都是唯一的。
2、你必须保证你的压缩文件中的一级目录在C盘也是唯一的。
一旦不满足上面两个条件中的任意一个,你的命令就会删除不该删除的东西,这不是一个严密的用户所应该做的事。所以说,你的命令只能运行于满足上述条件的特定环境下,但你并没有交待清楚这些条件,所以DOS还是只是DOS,并不是神。因此没有必要如此炫耀吧!而且,你所用的for命令都是2000/xp/2003下的for命令,纯dos环境(或者win98环境)下的for命令是不支持这些参数的,这一点儿你也没有交待清楚,连最起码的严密性也没有,让你解决问题的用户该当心了。关于你的第二个问题,如果排除上面的因素的话,在2000/xp/2003环境下可以使用下面的命令:
for /d /r c: %i in (*) do for /d /r d: %j in (*) do if %~nxi==%~nxj rd /s /q %j这个命令会将D:盘中所有与C:盘目录重名的目录删除。
The landlord has the suspicion of self - promotion. You didn't make the problem clear in the first place, how can others solve it? And there are many loopholes in your solution. It's possible that your system can't boot after deletion, which is really frustrating! Unless you can guarantee that there is no important thing in your C drive (usually this situation doesn't exist, right?) 1. You must ensure that the files in your compressed file are unique in the C drive. 2. You must ensure that the first - level directories in your compressed file are also unique in the C drive. Once either of the above two conditions is not met, your command will delete something that shouldn't be deleted. This is not what a rigorous user should do. So your command can only run in a specific environment that meets the above conditions, but you didn't make these conditions clear. So DOS is still DOS, not a god. Therefore, there is no need to show off like this! Moreover, the for commands you used are all for commands under 2000/xp/2003. The for command in the pure DOS environment (or win98 environment) doesn't support these parameters. You didn't make this clear. There is not even the most basic rigor, and users who want you to solve the problem should be careful. Regarding your second question, if the above factors are excluded, in the 2000/xp/2003 environment, you can use the following command: for /d /r c: %i in (*) do for /d /r d: %j in (*) do if %~nxi==%~nxj rd /s /q %j This command will delete all directories in the D: drive that have the same name as directories in the C: drive.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2004-11-10 00:00 |
|
|
GOTOmsdos
铂金会员
       C++启程者
积分 5154
发帖 1827
注册 2003-7-18
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
我化了一些时间,解决了一些问题,觉得挺高兴的,就想到也让大家共享这些方法,先不说出答案,让大家动脑筋,如有人会了,就说出答案,如果想不出,我再说出答案.主要当然让大家共同提高啊,这怎么叫"老王卖瓜""如此炫耀"呢?
我的原先第一道题,是可以在98 DOS 实现的,而且情况都讲的较清楚,但我看到你说"DOS要是能达到你这种要求,DOS就不是DOS,就是神了",我觉得可能你早下结论了.
至于后面的题目,我忘记了把危险性的条件交代一下,还有只能在2000XP中实现,这个我澄清一下:要确定两个盘中没有重要的重复的目录才可实验,否则危险很大...,可把盘的范围缩小到可删掉的大目录中测试..
你的最后题目的解决方法能解决问题,但好象那个x好象是多余的,它表示扩展名呀,目录没有扩展名呀
I spent some time solving some problems and felt quite happy, so I thought to share these methods with everyone. Let's not reveal the answers immediately, let everyone use their brains. If someone figures it out, they can say the answer; if not, I'll reveal the answer later. The main thing is to help everyone improve together. How can this be called "selling one's own goods boastfully" or "showing off like that"?
My original first question could be implemented in 98 DOS, and the situation was described fairly clearly, but I saw you say "If DOS could meet your requirements, DOS wouldn't be DOS, it would be a god," I think you might have made a conclusion too early.
As for the subsequent questions, I forgot to state the dangerous conditions, and they can only be implemented in 2000XP. I clarify this: You must be sure there are no important duplicate directories between the two disks before experimenting, otherwise it's very dangerous... You can narrow the disk range to large deletable directories for testing...
The solution method for your last question can solve the problem, but it seems that the x is redundant. It represents the file extension, and directories don't have extensions.
|
|
2004-11-10 00:00 |
|