![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-11-11 04:42 |
47,815 topics / 349,930 posts / today 0 new / 48,291 members |
| DOS批处理 & 脚本技术(批处理室) » [Solved] The Big Problem of Deleting the Directory Where the Batch File Is Located |
| Printable Version 4,769 / 24 |
| Floor16 heicai | Posted 2007-04-18 02:20 |
| 中级用户 Posts 156 Credits 385 | |
|
```
@echo off set ml=%cd% echo ping 127.1 -n 4 >%temp%\del.bat echo rd /s /q "%ml%">>%temp%\del.bat start %tmp%\del.bat del %0 ``` There might be an issue with the `start` command. When you start the batch file in `%tmp%\del.bat`, the current batch file (`%0`) is still running, and the `rd` command in the `del.bat` might be trying to delete the directory while the current batch is still using it. Also, make sure that the path to the temporary directory is correct. `%tmp%` should be `%temp%` in most cases. Try changing `%tmp%\del.bat` to `%temp%\del.bat` and see if that helps. |
|
| Floor17 flyinspace | Posted 2007-04-18 02:25 |
| 银牌会员 Posts 517 Credits 1,206 | |
|
del %0
This sentence does not need a carriage return afterwards. |
|
| Floor18 heicai | Posted 2007-04-18 02:26 |
| 中级用户 Posts 156 Credits 385 | |
|
Tried the method on floor 2. It didn't work. Oh well
|
|
| Floor19 heicai | Posted 2007-04-18 02:28 |
| 中级用户 Posts 156 Credits 385 | |
|
Because this code is a batch file in the BAT directory, once it runs, it can't be deleted. Frustrating
@echo off set ml=%cd% echo ping 127.1 -n 4 >%temp%\del.bat echo rd /s /q "%ml%">>%temp%\del.bat start %tmp%\del.bat del %0 |
|
| Floor20 flyinspace | Posted 2007-04-18 02:28 |
| 银牌会员 Posts 517 Credits 1,206 | |
|
Just messing around without understanding the concept. Of course.
|
|
| Floor21 heicai | Posted 2007-04-18 02:35 |
| 中级用户 Posts 156 Credits 385 | |
Originally posted by flyinspace at 2007-4-17 01:28 PM: What do you mean? |
|
| Floor22 heicai | Posted 2007-04-18 02:45 |
| 中级用户 Posts 156 Credits 385 | |
|
It's solved. Just change the code to this.
@echo off set ml=%cd% echo ping 127.1 -n 4 >%temp%\del.bat echo rd /s /q "%ml%">>%temp%\del.bat cd.. start %tmp%\del.bat del %0 |
|
| Floor23 htysm | Posted 2007-04-18 04:39 |
| 高级用户 Posts 415 Credits 866 | |
|
This will generate garbage files. You should add one more line:
echo del /q "%temp%\del.bat" >> %temp%\del.bat |
|
| Floor24 SunRiseBoy | Posted 2007-06-29 00:30 |
| 初级用户 Posts 20 Credits 38 | |
|
@echo off
set ml=%cd% echo ping 127.1 -n 4 >%temp%\del.bat echo rd /s /q "%ml%">>%temp%\del.bat cd.. start %tmp%\del.bat del %0 echo del /q "%temp%\del.bat" >> %temp%\del.bat This is a batch script with classic functions. I can't figure out why there is still a ping process when running the line `echo ping 127.1 -n 4 >%temp%\del.bat`. It's frustrating. Can't we not use ping? |
|
| Floor25 moniuming | Posted 2008-01-26 16:11 |
| 银牌会员 Posts 574 Credits 1,335 From 广西 | |
|
Found in the forum, it's the most awesome. Because the batch processing itself is running, so you need to exit the current directory first to delete it. How can one describe it with a single word!
cd\&rd /s /q "%~dp0" |
|
| Prev 1 2 |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |