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

查看:498
本文介绍了如何在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.

有命令吗?

推荐答案

您可以使用此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天全站免登陆