Scripts Thread, Request : Script to Delete All But 10 Newest Files in Folder in Coding and Web Development; I consider myself pretty competent in batch file scripting, but this one has me stumped.
We have roaming profile users ...
-
25th September 2006, 11:38 AM #1 Request : Script to Delete All But 10 Newest Files in Folder
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!"
-
-
IDG Tech News
-
25th September 2006, 11:57 AM #2 Re: Request : Script to Delete All But 10 Newest Files in Fo
Code:
find . -mtime +10 -type f -exec rm -rf {} \; will delete files modified more than 10 days ago - requires cygwin or linux
-
-
25th September 2006, 12:12 PM #3
- Rep Power
- 0
Re: Request : Script to Delete All But 10 Newest Files in Folder
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.
-
-
25th September 2006, 12:27 PM #4
- Rep Power
- 0
Re: Request : Script to Delete All But 10 Newest Files in Folder
The *nix solutions are all quite elegant but if you can't install Cygwin or Interix/SfU on your server then use FOR /F
Code:
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.
-
SHARE: 
Similar Threads
-
By FN-GM in forum Scripts
Replies: 15
Last Post: 22nd December 2007, 04:44 PM
-
By FN-GM in forum Scripts
Replies: 8
Last Post: 17th November 2007, 09:04 PM
-
By sidewinder in forum Windows
Replies: 2
Last Post: 20th March 2007, 02:49 PM
-
Replies: 1
Last Post: 21st January 2007, 02:51 PM
-
By arctan in forum Scripts
Replies: 5
Last Post: 5th March 2006, 01:22 PM
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules