![]() |
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-09-14 17:36 |
47,812 topics / 349,917 posts / today 0 new / 48,268 members |
| DOS批处理 & 脚本技术(批处理室) » [Solved] The Big Problem of Deleting the Directory Where the Batch File Is Located |
| Printable Version 4,254 / 24 |
| Floor1 heicai | Posted 2007-04-17 22:45 |
| 中级用户 Posts 156 Credits 385 | |
|
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 ] |
|
| Floor2 flyinspace | Posted 2007-04-17 23:33 |
| 银牌会员 Posts 517 Credits 1,206 | |
|
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 |
|
| Floor3 bw070 | Posted 2007-04-18 00:14 |
| 中级用户 Posts 137 Credits 292 | |
|
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 ] |
|
| Floor4 everest79 | Posted 2007-04-18 00:34 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
Delete after terminating the explorer process
|
|
| Floor5 flyinspace | Posted 2007-04-18 01:07 |
| 银牌会员 Posts 517 Credits 1,206 | |
|
Oh, I'm speechless. There are simple methods available, but all are used in a really complicated way.
|
|
| Floor6 heicai | Posted 2007-04-18 01:12 |
| 中级用户 Posts 156 Credits 385 | |
Originally posted by flyinspace at 2007-4-17 10:33 AM: 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? |
|
| Floor7 flyinspace | Posted 2007-04-18 01:16 |
| 银牌会员 Posts 517 Credits 1,206 | |
|
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. |
|
| Floor8 everest79 | Posted 2007-04-18 01:19 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
The directory where the batch file is located is "%~dp0"
|
|
| Floor9 heicai | Posted 2007-04-18 01:20 |
| 中级用户 Posts 156 Credits 385 | |
|
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. |
|
| Floor10 everest79 | Posted 2007-04-18 01:25 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
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
|
|
| Floor11 flyinspace | Posted 2007-04-18 01:27 |
| 银牌会员 Posts 517 Credits 1,206 | |
|
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.
|
|
| Floor12 heicai | Posted 2007-04-18 01:30 |
| 中级用户 Posts 156 Credits 385 | |
Originally posted by everest79 at 2007-4-17 12:25 PM: The batch processing in each folder is to delete that folder after clicking. |
|
| Floor13 everest79 | Posted 2007-04-18 01:35 |
| 金牌会员 Posts 1,127 Credits 2,564 | |
|
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
|
|
| Floor14 heicai | Posted 2007-04-18 01:41 |
| 中级用户 Posts 156 Credits 385 | |
|
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
Just don't know what %%~nxp means? [ Last edited by heicai on 2007-4-17 at 12:42 PM ] |
|
| Floor15 flyinspace | Posted 2007-04-18 01:45 |
| 银牌会员 Posts 517 Credits 1,206 | |
|
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 |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |