批处理文件,删除除特定天数以外的N天以上的文件夹 [英] Batch file to delete folders older than N days except specific ones

查看:87
本文介绍了批处理文件,删除除特定天数以外的N天以上的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个批处理文件,以删除超过6个月未使用的配置文件,同时保留诸如管理员,默认用户,所有用户等"之类的特定配置文件.

I'm looking to make a batch file to delete profiles that haven't been used in over 6 months while retaining specific ones such as "Administrator, Default User, All Users, etc."

我已经搜索了所有内容,并且找到了一种删除旧文件/文件夹的方法:

I've searched all around and have found a way to remove older files/folders:

forfiles.exe/p D:\ Files/s/m ./d -7/c"cmd/c del @file"

forfiles.exe /p D:\Files /s /m . /d -7 /c "cmd /c del @file"

但是无法通过"forfiles"设置例外

But there's no way of making an exception with "forfiles"

我还找到了一种删除文件/文件夹的方法,但有例外:

I've also found a way to delete files/folders with exceptions:

对于(* .exe)中的%% i,如果不是"%% i" ==文件名" del/q"%% i"

for %%i in (*.exe) do if not "%%i"=="file name" del /q "%%i"

但这会删除每个文件/文件夹,而不仅仅是旧文件/文件夹.

But that'll remove every file/folder and not just older ones.

我的情况: 我负责运行WinXP的数百个工作站.有几个用户登录到这些计算机,我不想删除其帐户.只有那些没有登录过的用户,每个工作站中的3个或4个永久帐户始终保持相同.因此,如果在6个月内没有人登录到管理员帐户,我希望它保持不变.我无法将forfile放入所有这些工作站或任何其他软件中,因此我的能力受到限制.

My scenario: I take care of hundreds of workstations which run WinXP. There are several users that log in to these computers and I wouldn't want to delete their accounts. Only those who haven't logged in in a while and the exception of 3 or 4 permanent accounts in each workstation which are always the same. So, if no one has logged in to an Administrator account in over 6 months, I would like for it to stay intact. I can't drop forfiles into all of these workstations or any other piece of software so I'm limited on my capabilities.

任何人都可以帮忙吗?

推荐答案

首先,制作一个带有文件夹例外的文本文件,将每行一个文件夹用双引号引起来.
将异常文件放在您的%userprofile%文件夹中.
例如exception.txt:

At first, make a text file with the folder exceptions, put one folder per line in double quotes.
Put the exception file in your %userprofile% folder.
example exception.txt:

"Default"
"Default User"
"All Users"


Batch代码:


Batch code:

for /f "delims=" %%a in ('forfiles /p "%userprofile%\.." /d -180 /c "cmd /c if @isdir==TRUE echo @file"^|findstr /vig:"%userprofile%\exception.txt"') do echo rd /s /q "%%~a"

查看输出并删除echo命令(如果看起来不错).
Forfiles在XP Prof.或更高版本中可用,不是XP Home .

Look at the output and remove the echo command, if it looks good.
Forfiles is available in XP Prof. or better, not XP Home.

这篇关于批处理文件,删除除特定天数以外的N天以上的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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