有问题批处理文件来删除指定位置的文件和文件夹 [英] having issue batch file to delete files and folders of a specified location

查看:79
本文介绍了有问题批处理文件来删除指定位置的文件和文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您已经写了一个批处理文件来删除指定位置的文件和文件夹

一切都很好,但问题是当机器中没有这样的F:驱动器时

批处理文件删除保存文件夹的内容。

任何人都可以帮助修改批处理文件并编写条件来检查驱动器是否存在



我的批处理文件



set folder =F:\PortalViewState

cd / d%文件夹%

for / Fdelims =%% i in('dir / b')do(rmdir%% i/ s / q || del %% i/ s / q)

Hi have written a batch file to delete files and folders of a specified location
all is fine but the issue is that when there is no such F: drive in the machine then
the batch file delete the content of the folder where it has been kept .
Can any one help to modify the batch file and to write a condition to check wether that drive is present or not

My batch file

set folder="F:\PortalViewState"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)

推荐答案

使用 IF 命令来测试文件或目录存在。在命令提示符下键入help if以获取详细信息。
Use the IF command to test whether a file or directory exists. Type "help if" at the command prompt for details.


这篇关于有问题批处理文件来删除指定位置的文件和文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆