如何在 Windows 中自动删除文件夹中的所有文件

灰暗的星星灰暗的星星灰暗的星星灰暗的星星灰暗的星星
 

How to Automatically Delete All Files in a Folder in Windows

如何在 Windows 中自动删除文件夹中的所有文件

To clean up a folder on a regular basis, you can configure Windows to automatically delete all files and folders in a folder. Here’s how.

若要定期清理文件夹,可以将 Windows 配置为自动删除文件夹中的所有文件和文件夹。以下是如何做到这一点。

In Windows, deleting files in a folder is as easy as selecting all of them and then pressing the DELETE key. However, if you want to automatically delete all files in a folder then the story will be different. You have to go through some hoops to get the job done.

在 Windows 中,删除文件夹中的文件只需选择所有文件,然后按 DELETE 键即可。但是,如果您想自动删除一个文件夹中的所有文件,那么故事将是不同的。你必须经过一些程序才能完成这项工作。

 

Recently, I received an email from a WL user asking me a way to automatically delete all the files and folders in a folder on schedule. Coincidentally, I’ve been doing that for many years now with my Screenshots folder. To be more precise, I sync my Screenshots folder with OneDrive and configured Windows Task Scheduler to delete all files in the Screenshot folder as soon as I log into the system. Since all the files are already synced with OneDrive, there is no data loss. It just cleans the clutter. You can do that same with any folder you want.

最近,我收到一封来自 WL 用户的邮件,问我如何按时自动删除文件夹中的所有文件和文件夹。巧合的是,我已经用我的截图文件夹做了很多年了。更准确地说,我用 OneDrive 同步了我的 Screenshots 文件夹,并配置了 Windows 任务调度程序,一旦我登录到系统,就删除了 Screenshot 文件夹中的所有文件。因为所有的文件都已经与 OneDrive 同步,所以没有数据丢失。它只是清理杂物。你可以对任何你想要的文件夹做同样的事情。

So, without further ado, let me show the way you can automatically delete all files in a folder on schedule in Windows.

所以,废话少说,让我来演示一下如何在 Windows 中按计划自动删除一个文件夹中的所有文件。

Note: I’m showing this in Windows 10 but you can follow the same steps in Windows 7 and 8. Also, don’t confuse the below method with Storage Sense feature in Windows 10. Storage Sense will only clean/delete files in system folders like Downloads, temp, etc. You cannot assign custom folders to it.

注意: 我在 Windows 10中展示了这一点,但是你可以在 Windows 7和8中遵循同样的步骤。另外,不要将下面的方法与 Windows 10中的存储感知功能混淆。Storage Sense 只会清理/删除系统文件夹中的文件,比如下载文件、临时文件等。不能为其分配自定义文件夹。

Delete All Files Automatically in a Folder

自动删除文件夹中的所有文件

Since Windows has no simple way to automatically delete all files and folders in a folder, you need to create a batch script to get the job done. After creating that, you can use the task scheduler to execute the batch script on a schedule.

由于 Windows 没有简单的方法自动删除文件夹中的所有文件和文件夹,因此需要创建一个批处理脚本来完成这项工作。创建该脚本之后,您可以使用任务调度程序在调度表上执行批处理脚本。

 

1. The first thing we need to do is create a batch script aka, .bat file. To do that, right-click on the desktop and select “New → Text Document“.

1.我们需要做的第一件事是创建一个批处理脚本,也就是,。蝙蝠锉。要做到这一点,右键单击桌面并选择“新建→文本文档”。

2. This action will create a new text file. Name the text file as “AutoDelete.bat“. You can name the file anything you want. Just make sure that you replace .txt extension with .bat.

图2。此操作将创建一个新的文本文件。将文本文件命名为“ AutoDelete.bat”。你可以给文件起任何名字。只要确保你能够用.bat替换掉.txt。

 

3. After creating the .bat file, right-click on it and select the “Edit” option. This option will open the file in your default text editor, Notepad. In the Notepad, copy and paste the below code. Replace the dummy path with the actual folder path.

图3。在创建了。在 bat 文件中,右键单击它并选择“ Edit”选项。此选项将在默认文本编辑器“记事本”中打开该文件。在记事本中,复制并粘贴下面的代码。用实际的文件夹路径替换虚拟路径。

set folder="D:\replace\dummy\folder\path"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
Delete-all-files-in-a-folder-paste-code

4. Save the file by pressing the Ctrl + S keyboard shortcut or by selecting the “File → Save” option. After saving, close the file.

图4。通过按 Ctrl + s/快捷键或选择“文件→保存”选项来保存文件。保存之后,关闭文件。

5. After creating the file, use the Task Scheduler to schedule the batch file. I’ve already written a detailed step by step guide on how to do it. Do follow the article and you will be done.

5.创建文件后,使用“任务计划程序”调度批处理文件。我已经写了一个详细的一步一步的指导如何做到这一点。照着这篇文章做,你就会完成。

In case you are wondering, all the files and folders deleted from the target folder will still be available in the Recycle Bin. This makes it easy to restore them if need be.

如果您想知道的话,从目标文件夹中删除的所有文件和文件夹在回收站中仍然可用。这使得在需要的时候恢复它们变得容易。

I hope that helps. If you are stuck or need some help, comment below and I will try to help as much as possible.

我希望这能有所帮助。如果你遇到困难或者需要帮助,请在下面评论,我会尽可能的帮助你。

提交评论


安全码
刷新

 

自1996年以来,公司一直专注于域名注册、虚拟主机、服务器托管、网站建设、电子商务等互联网服务,不断践行"提供企业级解决方案,奉献个性化服务支持"的理念。作为戴尔"授权解决方案提供商",同时提供与公司服务相关联的硬件产品解决方案。
 

联系方式

地址:河南省郑州市经五路2号

电话:0371-63520088 

QQ:76257322

网站:800188.com

电邮:该邮件地址已受到反垃圾邮件插件保护。要显示它需要在浏览器中启用 JavaScript。

微信:用企业微信联系