如何在 Windows 中的命令提示符下删除特定目录中的文件/子文件夹 [英] How to delete files/subfolders in a specific directory at the command prompt in Windows

查看:17
本文介绍了如何在 Windows 中的命令提示符下删除特定目录中的文件/子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比如说,有一个名为 %pathtofolder% 的变量,因为它清楚地表明它是一个文件夹的完整路径.

Say, there is a variable called %pathtofolder%, as it makes it clear it is a full path of a folder.

我想删除此目录中的每个文件和子文件夹,但不删除目录本身.

I want to delete every single file and subfolder in this directory, but not the directory itself.

但是,可能会出现诸如此文件/文件夹已在使用中"之类的错误……发生这种情况时,它应该继续并跳过该文件/文件夹.

But, there might be an error like 'this file/folder is already in use'... when that happens, it should just continue and skip that file/folder.

有什么命令可以解决这个问题吗?

Is there some command for this?

推荐答案

您可以使用此 shell 脚本清理 C:Temp 来源:

You can use this shell script to clean up the folder and files within C:Temp source:

del /q "C:Temp*"
FOR /D %%p IN ("C:Temp*.*") DO rmdir "%%p" /s /q

创建一个包含上述命令的批处理文件(例如,delete.bat).到delete.bat文件所在的位置,然后运行命令:delete.bat

Create a batch file (say, delete.bat) containing the above command. Go to the location where the delete.bat file is located and then run the command: delete.bat

这篇关于如何在 Windows 中的命令提示符下删除特定目录中的文件/子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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