简体   繁体   English

删除所有以数字为名称的文件夹

[英]Delete all folders that have numbers as names

I can find a way to use regex with the rmdir command on Windows.我可以找到一种在 Windows 上使用正则表达式和 rmdir 命令的方法。 I need to delete any folder that has names as follows:我需要删除任何名称如下的文件夹:

  • 0855485700 0855485700
  • 54840287805 54840287805
  • 15749678 15749678
  • 12569 12569
  • 9659432665665 9659432665665

Basically, I need something like rmdir /s /q %USERPROFILE%\AppData\Local\FolderA\SubFolderB\[0-9] *基本上,我需要类似rmdir /s /q %USERPROFILE%\AppData\Local\FolderA\SubFolderB\[0-9] *

[0-9] * being a regular expression to match all folders with names starting with numbers. [0-9] * 是一个正则表达式,用于匹配名称以数字开头的所有文件夹。

A little background: folders are created regularly by an application.一点背景知识:文件夹是由应用程序定期创建的。 The folders have random names, but the folder names have something in common: they are always numbers.文件夹的名称是随机的,但文件夹名称有一些共同点:它们总是数字。

I need to schedule a deletion of those folders on Windows, so I'm trying to create a task to run a command every month.我需要安排删除 Windows 上的这些文件夹,所以我正在尝试创建一个任务来每月运行一个命令。 But I can't find a way to use a pattern for this.但我找不到为此使用模式的方法。 And I can't delete all the folders inside the immediate parent folder.而且我无法删除直接父文件夹中的所有文件夹。 I can only delete the fodlers with numbers as names.我只能删除以数字为名称的文件夹。

Thanks in advance for any help.提前感谢您的帮助。

As I couldn't find a way to target all folders with names starting with numbers with a single regular expression, I ended up creating a batch file with a for loop that targets all files starting with 0 or 1 or 2 or 3 or 4 or 5 or 6 or 7 or 8 or 9.由于我找不到使用单个正则表达式来定位名称以数字开头的所有文件夹的方法,因此我最终创建了一个带有for循环的批处理文件,该循环针对以 0 或 1 或 2 或 3 或 4 或开头的所有文件5 或 6 或 7 或 8 或 9。

Here's the content of the file:这是文件的内容:

for /d %%i in (%USERPROFILE%\AppData\Local\Google\DriveFS\0* %USERPROFILE%\AppData\Local\FolderA\SubFolderB\1* %USERPROFILE%\AppData\Local\FolderA\SubFolderB\2* %USERPROFILE%\AppData\Local\FolderA\SubFolderB\3* %USERPROFILE%\AppData\Local\FolderA\SubFolderB\4* %USERPROFILE%\AppData\Local\FolderA\SubFolderB\5* %USERPROFILE%\AppData\Local\FolderA\SubFolderB\6* %USERPROFILE%\AppData\Local\FolderA\SubFolderB\7* %USERPROFILE%\AppData\Local\FolderA\SubFolderB\8* %USERPROFILE%\AppData\Local\FolderA\SubFolderB\9*) do @rmdir "%%i" /q

If anyone can think of a better solution let me know.如果有人能想到更好的解决方案,请告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM