|
jpowe
初级用户
 
积分 152
发帖 20
注册 2004-3-3
状态 离线
|
『楼 主』:
[求助]用批处理删除文件的问题(已解决)
使用 LLM 解释/回答一下
想用批处理删除c:\Documents and Settings\CCTV\My Documents\YYGH\DATA文件夹和子文件夹里面的文件,保留子文件夹,请帮忙!谢谢
cd c:\Documents and Settings\CCTV\My Documents\YYGH\DATA
del *.* /s /q 这是我写的,但是觉得有问题,
1.如果没有CCTV这个路径,会删除本机所有文件
2.如果这个脚本启动于C盘外的其他分区上,那么删除的是脚本启动目录下的所有文件 (不知道如何避免这种情况)
Last edited by jpowe on 2008-3-10 at 12:39 AM ]
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 ]
|
|
2008-3-8 00:52 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
|
2008-3-8 01:45 |
|
|
lovelymorning
初级用户
 
积分 131
发帖 72
注册 2008-2-24
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
del /s /q "%USERPROFILE%\My Documents\YYGH\DATA\*.*"
这个是删除当前登陆用户的我的文档下的yygh\data文件夹以及下面子目录的所有文件
不管这个脚本放在哪里,删除的都是这个地方
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.
|
|
2008-3-8 13:43 |
|
|
jpowe
初级用户
 
积分 152
发帖 20
注册 2004-3-3
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
Originally posted by lovelymorning at 2008-3-8 01:43 PM:
del /s /q "%USERPROFILE%\My Documents\YYGH\DATA\*.*"
这个是删除当前登陆用户的我的文档下的yygh\data文件夹以及下面子目录的所有文件
不管这个脚本放在哪里,删除的都是这个地方
如果不是当前登陆用户,应该如何写?
If it's not the current logged-in user, how should it be written?
|
|
2008-3-8 14:09 |
|
|
jpowe
初级用户
 
积分 152
发帖 20
注册 2004-3-3
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Originally posted by terse at 2008-3-8 01:45 AM:
路径加“”试
请问""如何加?有两行代码
不好意思.我是菜鸟,请帮忙.谢谢你了
Originally posted by terse at 2008-3-8 01:45 AM:
Try adding quotes around the path
Excuse me. I'm a newbie, please help. Thank you
|
|
2008-3-8 14:10 |
|
|
terse
银牌会员
    
积分 2404
发帖 946
注册 2005-9-8
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
就一行应该可以
del “c:\Documents and Settings\CCTV\My Documents\YYGH\DATA\*.*” /s /q
It's just one line.
del "c:\Documents and Settings\CCTV\My Documents\YYGH\DATA\*.*" /s /q
|

简单!简单!再简单! |
|
2008-3-8 16:02 |
|
|
jpowe
初级用户
 
积分 152
发帖 20
注册 2004-3-3
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
Originally posted by terse at 2008-3-8 04:02 PM:
就一行应该可以
del “c:\Documents and Settings\CCTV\My Documents\YYGH\DATA\*.*” /s /q
用del “c:\Documents and Settings\CCTV\My Documents\YYGH\DATA\*.*” /s /q 做的BAT文件运行无效 提示找不到路径
Originally posted by terse at 2008-3-8 04:02 PM:
Just one line should be okay
del "c:\Documents and Settings\CCTV\My Documents\YYGH\DATA\*.*" /s /q
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
|
|
2008-3-8 20:54 |
|
|
suntb
高级用户
   
积分 581
发帖 277
注册 2006-12-23
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by jpowe at 2008-3-8 00:52:
想用批处理删除c:\Documents and Settings\CCTV\My Documents\YYGH\DATA文件夹和子文件夹里面的文件,保留子文件夹,请帮忙!谢谢
cd c:\Documents and Settings\CCTV\My Documents\YYGH\DATA
del *.* /s /q 这是我写的,但是觉得有问题,
1.如果没有CCTV这个路径,会删除本机所有文件
2.如果这个脚本启动于C盘外的其他分区上,那么删除的是脚本启动目录下的所有文件 (不知道如何避免这种情况)
第2点的问题你可以在cd后加一个/d开关,也就是
cd /d "c:\Documents and Settings\CCTV\My Documents\YYGH\DATA"
第一个问题也就是说你无法确定这个CCTV文件夹是否存在?
Originally posted by jpowe at 2008-3-8 00:52:
Want to use batch processing to delete the files in the folder c:\Documents and Settings\CCTV\My Documents\YYGH\DATA and its 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 feel 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 from another partition outside the C drive, then it will delete all files in the script's starting directory (don't know how to avoid this situation)
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?
|
|
2008-3-8 23:26 |
|
|
suntb
高级用户
   
积分 581
发帖 277
注册 2006-12-23
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
刚才仔细看了下楼主的要求 发现有些自相矛盾
既然已经删除DATA文件夹了,又怎么会还存在子文件夹
是不是要删除这个DATA文件夹及其所有子文件夹下的文件,但是保留整个文件夹目录结构?
如果是这样的话,可以试试下面代码
@echo off
set pth=c:\Documents and Settings\CCTV\My Documents\YYGH\DATA
if exist "%pth%" (del /q /s "%pth%">nul) else (echo 不存在目标文件夹 "%pth%")
pause
Last edited by suntb on 2008-3-8 at 11:43 PM ]
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
@echo off
set pth=c:\Documents and Settings\CCTV\My Documents\YYGH\DATA
if exist "%pth%" (del /q /s "%pth%">nul) else (echo The target folder "%pth%" does not exist)
pause
Last edited by suntb on 2008-3-8 at 11:43 PM ]
|
|
2008-3-8 23:34 |
|
|
jpowe
初级用户
 
积分 152
发帖 20
注册 2004-3-3
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by suntb at 2008-3-8 11:34 PM:
刚才仔细看了下楼主的要求 发现有些自相矛盾
既然已经删除DATA文件夹了,又怎么会还存在子文件夹
是不是要删除这个DATA文件夹及其所有子文件 ...
你的理解完全正确,你的CODE我也用过,很好.现在又有一个问题是我想加多几个删除的路径,应该如何写,麻烦你了.
比如:要删除
c:\Documents and Settings\CCTV\My Documents\YYGH\DATA
c:\Documents and Settings\CCTV\My Documents\YYGH\DA
因为\YYGH\ 路径下有些文件不想被删除,但要删除
\DATA\和\DA\下的文件和子文件夹下的文件.,请帮忙.谢谢
Originally posted by suntb at 2008-3-8 11:34 PM:
Just now I carefully looked at the building owner's requirements and found some contradictions
Since the DATA folder has been deleted, how can there still be subfolders
Is it necessary to delete this DATA folder and all its subfiles...
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
|
|
2008-3-9 20:46 |
|
|
suntb
高级用户
   
积分 581
发帖 277
注册 2006-12-23
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
@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 ]
```
@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 ]
|
|
2008-3-9 21:32 |
|
|
jpowe
初级用户
 
积分 152
发帖 20
注册 2004-3-3
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
Originally posted by suntb at 2008-3-9 09:32 PM:
@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 ...
请问中文名字的文件夹一样也可以在括号里面()添加吗?
Can folders with Chinese names be added in the parentheses () as well?
|
|
2008-3-9 22:08 |
|
|
suntb
高级用户
   
积分 581
发帖 277
注册 2006-12-23
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
删除c:\Documents and Settings\CCTV\My Documents\YYGH下所有子文件夹里面的文件,保留YYGH文件夹下的文件及其子文件夹结构
@echo off
set "pth=c:\Documents and Settings\CCTV\My Documents\YYGH"
for /r "%pth%" %%i in (.) do (if not "%%i"=="%pth%\." (del /q /s "%%i\*.*" 1>nul))
pause
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
@echo off
set "pth=c:\Documents and Settings\CCTV\My Documents\YYGH"
for /r "%pth%" %%i in (.) do (if not "%%i"=="%pth%\." (del /q /s "%%i\*.*" 1>nul))
pause
|
|
2008-3-9 22:50 |
|
|
suntb
高级用户
   
积分 581
发帖 277
注册 2006-12-23
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
这样是否符合楼主的要求了?
不需要指定子文件夹名 包括中文及带空格的子文件夹都能处理
Does this meet the LZ's requirements? No need to specify the subfolder name, can handle Chinese and subfolders with spaces included
|
|
2008-3-9 22:51 |
|
|
jpowe
初级用户
 
积分 152
发帖 20
注册 2004-3-3
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by suntb at 2008-3-9 10:51 PM:
这样是否符合楼主的要求了?
不需要指定子文件夹名 包括中文及带空格的子文件夹都能处理
谢谢 suntb强大的处理能力!
Originally posted by suntb at 2008-3-9 10:51 PM:
Does this meet the requirements of the original poster?
No need to specify the subfolder name. It can handle subfolders including Chinese characters and spaces.
Thank you suntb for your powerful processing ability!
|
|
2008-3-10 00:38 |
|