删除所有文件夹,除了在Windows介绍最新2文件夹 [英] Delete all folders except 2 lastest folders in Windows
问题描述
我要删除从目录中的所有文件夹,除了最新的2个文件夹(最近更新日期)。我想通过一个小的命令行code做到这一点。我该怎么做?下面是code显示由最后修改时间排序的文件夹。
DIR / AD-H / OD
我试着用 FOR / D
命令。
为/ D跳过= 2令牌= *%中(DIR / AD-H / OD)G DO呼应要删除%G
不过,我得到了以下错误消息。
跳过= 2令牌= *在这个时候意外。
我该怎么办呢?
FOR / F在('DIR / B / AD-H跳过= 2 delims =%G / O -d')DO回声要删除%G
FOR / F
从处理输出行单引号
DIR ...
Delims =
更好。 标记= *
将在这里工作,但SUP presses前导空格。
/ B
来燮preSS头输出 DIR
/ O-D
的反向日期顺序。你想保留两跳过迪尔斯,在反向日期排序发生的FIRS。
...好回声
的安全措施。
I want to delete all the folders from a directory except the latest 2 folders (Last modified date). I want to do this by a small command line code. How do I do it? Below is the code to display folders sorted by last modified time.
dir /ad-h /od
I tried using FOR /D
command.
for /d "skip=2 tokens=*" %G in ("dir /ad-h /od") DO echo going to delete %G
But I got the below error message.
"skip=2 tokens=*" was unexpected at this time.
How do I do it?
for /f "skip=2 delims=" %G in ('dir /B /ad-h /o-d') DO echo going to delete %G
For /f
to process lines of "output" from single-quoted
DIR...
Delims=
is better. tokens=*
will work here, but suppresses leading spaces.
/b
to suppress header output from dir
/o-d
for REVERSE-date order. You want to KEEP the two skipped dirs, which occur FIRS in a reverse-date sort.
...good echo
safety measure.
这篇关于删除所有文件夹,除了在Windows介绍最新2文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!