OutToLunch Posted September 25, 2006 Posted September 25, 2006 I consider myself pretty competent in batch file scripting, but this one has me stumped. We have roaming profile users (Argh) for whom the Recent folder of links is totally out of control. Where it should have the last few files they opened, it has 200+ shortcuts in. Can anyone think of a programatical way to nuke all but the last 10 (for example) shortcuts in the folder, based on age? I can't nuke the whole folder and allow it to recreate itself as many of the users rely on "Recent Documents" rather than actually knowing where the hell they saved their work and I will have weeks of "My work is all gone!"
CyberNerd Posted September 25, 2006 Posted September 25, 2006 find . -mtime +10 -type f -exec rm -rf {} \; will delete files modified more than 10 days ago - requires cygwin or linux
ico2 Posted September 25, 2006 Posted September 25, 2006 try this (again, needs cygwin or linux): rm $(ls -Ac | tail -n $(echo $(($(ls -A| wc -l)-10)))) test it first and make sure you have backups.
NetworkGeezer Posted September 25, 2006 Posted September 25, 2006 The *nix solutions are all quite elegant but if you can't install Cygwin or Interix/SfU on your server then use FOR /F FOR /F "skip=10 delims=?" %a in ('DIR /o-d /b *.lnk') do DEL "%a" The delims=? is for file names containing white spaces. Oh yeah this assumes that the current directory is set to Recent Files of the relevant profile. Test it with @ECHO rather than DEL to see if it's picking up the correct files then use DEL when ready.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now