![]() |
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-08-12 06:13 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » [Help] Problem with deleting files using batch processing (solved) |
| Printable Version 5,654 / 15 |
| Floor1 jpowe | Posted 2008-03-08 00:52 |
| 初级用户 Posts 20 Credits 152 | |
|
Want to use batch processing to delete the files in the c:\Documents and Settings\CCTV\My Documents\YYGH\DATA folder and subfolders, while keeping the subfolders, please help! Thank you
cd c:\Documents and Settings\CCTV\My Documents\YYGH\DATA del *.* /s /q This is what I wrote, but I think there is a problem, 1. If there is no CCTV path, it will delete all files on the local machine 2. If this script is started on another partition outside the C drive, then it will delete all files in the script startup directory (don't know how to avoid this situation) [ Last edited by jpowe on 2008-3-10 at 12:39 AM ] |
|
| Floor2 terse | Posted 2008-03-08 01:45 |
| 银牌会员 Posts 946 Credits 2,404 | |
| Floor3 lovelymorning | Posted 2008-03-08 13:43 |
| 初级用户 Posts 72 Credits 131 | |
|
del /s /q "%USERPROFILE%\My Documents\YYGH\DATA\*.*"
This is to delete all files in the yygh\data folder and its subdirectories under My Documents of the currently logged-in user. No matter where this script is placed, it will delete this location. |
|
| Floor4 jpowe | Posted 2008-03-08 14:09 |
| 初级用户 Posts 20 Credits 152 | |
|
If it's not the current logged-in user, how should it be written?
|
|
| Floor5 jpowe | Posted 2008-03-08 14:10 |
| 初级用户 Posts 20 Credits 152 | |
Originally posted by terse at 2008-3-8 01:45 AM: Excuse me. I'm a newbie, please help. Thank you |
|
| Floor6 terse | Posted 2008-03-08 16:02 |
| 银牌会员 Posts 946 Credits 2,404 | |
|
It's just one line.
del "c:\Documents and Settings\CCTV\My Documents\YYGH\DATA\*.*" /s /q |
|
| Floor7 jpowe | Posted 2008-03-08 20:54 |
| 初级用户 Posts 20 Credits 152 | |
Originally posted by terse at 2008-3-8 04:02 PM: The BAT file made with del "c:\Documents and Settings\CCTV\My Documents\YYGH\DATA\*.*" /s /q is not working, and it prompts that the path is not found |
|
| Floor8 suntb | Posted 2008-03-08 23:26 |
| 高级用户 Posts 277 Credits 581 | |
Originally posted by jpowe at 2008-3-8 00:52: For the second point, you can add a /d switch after cd, that is cd /d "c:\Documents and Settings\CCTV\My Documents\YYGH\DATA" The first problem means that you can't be sure whether this CCTV folder exists? |
|
| Floor9 suntb | Posted 2008-03-08 23:34 |
| 高级用户 Posts 277 Credits 581 | |
|
Just now, I carefully looked at the requirements of the original poster and found that there are some contradictions.
Since the DATA folder has been deleted, how can there still be subfolders? Is it necessary to delete the files in this DATA folder and all its subfolders, but keep the entire folder directory structure? If that's the case, you can try the following code [ Last edited by suntb on 2008-3-8 at 11:43 PM ] |
|
| Floor10 jpowe | Posted 2008-03-09 20:46 |
| 初级用户 Posts 20 Credits 152 | |
Originally posted by suntb at 2008-3-8 11:34 PM: Your understanding is completely correct, and I have also used your CODE, which is very good. Now there is another problem. I want to add a few more paths to delete. How should I write it? It's troublesome for you. For example: to delete c:\Documents and Settings\CCTV\My Documents\YYGH\DATA c:\Documents and Settings\CCTV\My Documents\YYGH\DA Because there are some files under the \YYGH\ path that I don't want to delete, but I need to delete the files in the \DATA\ and \DA\ folders and the files in the subfolders. Please help. Thank you |
|
| Floor11 suntb | Posted 2008-03-09 21:32 |
| 高级用户 Posts 277 Credits 581 | |
|
```
@echo off set pth=c:\Documents and Settings\CCTV\My Documents\YYGH for %%i in (DATA DA) do (del /q /s "%pth%\%%i" 1>nul) pause ``` [ Last edited by suntb on 2008-3-9 at 09:33 PM ] |
|
| Floor12 jpowe | Posted 2008-03-09 22:08 |
| 初级用户 Posts 20 Credits 152 | |
|
Can folders with Chinese names be added in the parentheses () as well?
|
|
| Floor13 suntb | Posted 2008-03-09 22:50 |
| 高级用户 Posts 277 Credits 581 | |
|
Delete all files in all subfolders under c:\Documents and Settings\CCTV\My Documents\YYGH, while keeping the file and subfolder structure under the YYGH folder
|
|
| Floor14 suntb | Posted 2008-03-09 22:51 |
| 高级用户 Posts 277 Credits 581 | |
|
Does this meet the LZ's requirements? No need to specify the subfolder name, can handle Chinese and subfolders with spaces included
|
|
| Floor15 jpowe | Posted 2008-03-10 00:38 |
| 初级用户 Posts 20 Credits 152 | |
Originally posted by suntb at 2008-3-9 10:51 PM: Thank you suntb for your powerful processing ability! |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |