|
heicai
中级用户
  
积分 385
发帖 156
注册 2007-1-19
状态 离线
|
『楼 主』:
【已解决】删除批处理所在目录的大难题
使用 LLM 解释/回答一下
例如批处理del.bat文件在C:\Documents and Settings\Administrator\桌面\Bat\目录下。
我想删除Bat文件夹与其自身del.bat文件。
因为del.bat自身在运行所以无法删除该文件夹。哎
不知是否有牛人能帮其实现!
____________________以上已解决—————————————————
Last edited by heicai on 2007-4-17 at 01:46 PM ]
For example, the batch file del.bat is in the directory C:\Documents and Settings\Administrator\Desktop\Bat\.
I want to delete the Bat folder and its own del.bat file.
Because del.bat itself is running, so the folder cannot be deleted. Hey
I wonder if there are experts who can help achieve this!
____________________The above has been resolved—————————————————
Last edited by heicai on 2007-4-17 at 01:46 PM ]
|
|
2007-4-17 22:45 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
方法是可以乱来的。
不一定要局限于在本地建立文件。
可以在临时文件建立一个新的del文件啊。
内容如下:
cscript /nologo delay.vbs
rd /s /q "C:\Documents and Settings\Administrator\桌面\Bat"
del %0
在del文件中最后添加如下语句
echo WSCRIPT.sleep(5000)>delay.vbs
start %tmp%\del.bat
The method can be arbitrary.
It doesn't have to be limited to creating files locally.
You can create a new del file in a temporary file.
The content is as follows:
cscript /nologo delay.vbs
rd /s /q "C:\Documents and Settings\Administrator\桌面\Bat"
del %0
Add the following statement at the end of the del file
echo WSCRIPT.sleep(5000)>delay.vbs
start %tmp%\del.bat
|

知,不觉多。不知,乃求知 |
|
2007-4-17 23:33 |
|
|
bw070
中级用户
  
积分 292
发帖 137
注册 2007-4-3
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
以d:/1为例 你那个太长了我就不大了 ; )
@echo off
echo rmdir D:\1 /s /q >c:\1.bat
echo del c:\1.bat >>c:\1.bat
echo Windows Registry Editor Version 5.00>r.dll
echo >>r.dll
echo "Del"="C:\\1.bat">>r.dll
regedit -s r.dll
echo ☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
echo ★ ☆
echo ☆ 文件夹在重新启动或者注销后删除! ★
echo ★ ---------任意键退出!!---------- ☆
echo ☆ ★
echo ★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
pause
del r.dll
del d:\1\1.bat
见笑了 没有想出来立即删除那个正在运行的文件夹 不过想出个办法在注销或重新启动后彻底删除所有产生文件和目标文件夹
Last edited by bw070 on 2007-4-17 at 11:19 AM ]
Take D:/1 as an example. Yours is too long, so I won't make it long. ; )
@echo off
echo rmdir D:\1 /s /q >c:\1.bat
echo del c:\1.bat >>c:\1.bat
echo Windows Registry Editor Version 5.00>r.dll
echo >>r.dll
echo "Del"="C:\\1.bat">>r.dll
regedit -s r.dll
echo ☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
echo ★ ☆
echo ☆ The folder will be deleted after restart or logoff! ★
echo ★ ---------Press any key to exit!!---------- ☆
echo ☆ ★
echo ★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆
pause
del r.dll
del d:\1\1.bat
Just for fun. I didn't figure out how to immediately delete the running folder, but I came up with a way to completely delete all generated files and the target folder after logoff or restart.
Last edited by bw070 on 2007-4-17 at 11:19 AM ]
|
|
2007-4-18 00:14 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
终止了explorer进程再删
Delete after terminating the explorer process
|
|
2007-4-18 00:34 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
我寒,有简单的方法都不用,
全部都用好复杂的方法。
Oh, I'm speechless. There are simple methods available, but all are used in a really complicated way.
|

知,不觉多。不知,乃求知 |
|
2007-4-18 01:07 |
|
|
heicai
中级用户
  
积分 385
发帖 156
注册 2007-1-19
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by flyinspace at 2007-4-17 10:33 AM:
方法是可以乱来的。
不一定要局限于在本地建立文件。
可以在临时文件建立一个新的del文件啊。
内容如下:
cscript /nologo delay.vbs
rd /s /q "C: ...
谢谢你的方法。我试了很好用!
不过我还有个问题,假如bat文件夹假如是随机不定的名称,有办法获取到此文件夹名称吗?
Originally posted by flyinspace at 2007-4-17 10:33 AM:
The method can be arbitrary.
It doesn't have to be limited to creating files locally.
You can create a new del file in a temporary file.
The content is as follows:
cscript /nologo delay.vbs
rd /s /q "C: ...
Thank you for the method. I tried it and it works well!
But I have another question. If the bat folder is a random and undetermined name, is there a way to obtain the name of this folder?
|
|
2007-4-18 01:12 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
有是有,
不过最少要知道这个文件夹所在的地方吧?
要不一下子找出有许多bat文件的文件夹然后你一下全删完。不是要郁闷死了么。
或知道要删除的bat的文件名。。所在盘符也行。
不过。。。若多余一个,还是需要人工判断。。
There is there,
But at least you need to know where this folder is, right?
Otherwise, if you suddenly find a folder with many bat files and then delete them all at once. Wouldn't that be frustrating?
Or know the file name of the bat to be deleted. The drive letter where it is located is also okay.
But... if there are more than one, manual judgment is still needed.
|

知,不觉多。不知,乃求知 |
|
2007-4-18 01:16 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
批处理所在目录为"%~dp0"
The directory where the batch file is located is "%~dp0"
|
|
2007-4-18 01:19 |
|
|
heicai
中级用户
  
积分 385
发帖 156
注册 2007-1-19
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
我要实现的功能是这样的:
先将bat文件夹分别复制到桌面的a1,b2,c3,d4,haha,test,temp,……等等这些各个文件夹内。然后做一些工作后将它们文件夹全部删除。
C:\Documents and Settings\Administrator\桌面\temp\
要是能获取temp这个位置的文件夹设为一个环境变量就好了。不知道如何能截到这部分文件夹名称
The function I want to implement is like this:
First, copy the bat folder into each of the folders such as a1, b2, c3, d4, haha, test, temp, etc. on the desktop respectively. Then do some work and delete all those folders.
C:\Documents and Settings\Administrator\Desktop\temp\
It would be great if I could get the folder at this temp position set as an environment variable. I don't know how to intercept this part of the folder name.
|
|
2007-4-18 01:20 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
你在讲述你要求是最好先整理下思路,这样大家也好帮你,你复制到各个目录下的工作是由脚本还是手工来完成的?若脚本,你在此时即可建立删除列表;你复制完成后各目录执行的操作是手工启动还是由先前的复制脚本启动,若是脚本启动,那么,你前边的删除列表可以是以变量形式存在的,再下来就是你的删除要求,是最后一次性删除还是按工作顺序逐个删除,若是按工作顺序,那我前边讲的基本上没用,嘿嘿
You're talking about that first it's best to sort out your thoughts, so that everyone can help you. Is the work of you copying to various directories done by a script or manually? If it's a script, you can establish the deletion list at this time; after you finish copying, are the operations performed on each directory started manually or by the previous copy script? If it's started by a script, then the deletion list you mentioned earlier can exist in the form of variables. Then comes your deletion requirements. Is it a one-time deletion at the end or deletion one by one in accordance with the work order? If it's in accordance with the work order, then what I said earlier is basically useless, heh heh
|
|
2007-4-18 01:25 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
set 查看环境变量的地方。。
里面好象有你需要的东西。。。。你的意思我不太清楚。
set is where you check environment variables. It seems like there are things you need in it... I don't quite understand what you mean.
|

知,不觉多。不知,乃求知 |
|
2007-4-18 01:27 |
|
|
heicai
中级用户
  
积分 385
发帖 156
注册 2007-1-19
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Originally posted by everest79 at 2007-4-17 12:25 PM:
你在讲述你要求是最好先整理下思路,这样大家也好帮你,你复制到各个目录下的工作是由脚本还是手工来完成的?若脚本,你在此时即可建立删除列 ...
每个文件夹下的批处理都是点击后删除那个文件夹。
Originally posted by everest79 at 2007-4-17 12:25 PM:
You'd better organize your thoughts first when stating your requirements, so that everyone can help you better. Is the work of copying to various directories done by a script or manually? If it's a script, you can establish the deletion column at this time...
The batch processing in each folder is to delete that folder after clicking.
|
|
2007-4-18 01:30 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
那问题回到第8楼,你结合第二楼的方法来完成,你可以将"%~dp0"当作参数来启动del.bat
Then the problem returns to the 8th floor. You can complete it by combining the method of the 2nd floor. You can use "%~dp0" as a parameter to start del.bat
|
|
2007-4-18 01:35 |
|
|
heicai
中级用户
  
积分 385
发帖 156
注册 2007-1-19
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
对论坛内帖子进行考古后终于找到了答案!同时也万分感谢回答我问题的这些朋友,由于我等级低,今天的加分满了,不好意思
@echo off
for %%p in ("%cd%") do set temp=%%~nxp
echo %temp%
pause
就是不知道%%~nxp 这个是什么意思?
Last edited by heicai on 2007-4-17 at 12:42 PM ]
After excavating posts in the forum, I finally found the answer! Also, I am very grateful to these friends who answered my question. Because my level is low, today's points are full, sorry
@echo off
for %%p in ("%cd%") do set temp=%%~nxp
echo %temp%
pause
Just don't know what %%~nxp means?
Last edited by heicai on 2007-4-17 at 12:42 PM ]
|
|
2007-4-18 01:41 |
|
|
flyinspace
银牌会员
    
积分 1206
发帖 517
注册 2007-3-25
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
其实我觉得10楼的方法就很不错。。
rem 建立复制,删除列表,给一个例子。
echo %userprofile%\桌面\temp>>del.txt
::……你自己写完这个列表。
for /f "tokens=* " %%i in (del.txt) do (
rem 防止误删除文件
if exist "%%i" (
xcopy “你的文件” “%%i”
start “%%i\文件名"
)
)
for /f "tokens=* " %%i in (del.txt) do (
dir /b /s "%%i" | find /i "你复制的文件"
if not errorlevel 1 echo "%%i\你复制的文件"
)
本脚本未经过调试,实际使用时,若最后一句的echo 正确则可以改为rd /s /q
Actually, I think the method on floor 10 is quite good.
rem Create copy and delete lists, give an example.
echo %userprofile%\Desktop\temp>>del.txt
::... You finish writing this list yourself.
for /f "tokens=* " %%i in (del.txt) do (
rem Prevent accidental deletion of files
if exist "%%i" (
xcopy "your file" "%%i"
start "%%i\file name"
)
)
for /f "tokens=* " %%i in (del.txt) do (
dir /b /s "%%i" | find /i "the file you copied"
if not errorlevel 1 echo "%%i\the file you copied"
)
This script has not been debugged. When actually using it, if the last echo is correct, it can be changed to rd /s /q
|

知,不觉多。不知,乃求知 |
|
2007-4-18 01:45 |
|