mxgong
asked on
VBScript for removing files from folder
Hi All Experts
I would like to use Vbscript to remove some files from folder. These files are log files created automatically by application daily, I only want to keep 14 days log files and remove rest of them.
Anyone can tell me how to write a VBScript for this purpose? I am quite a new person to VB script.
Any help would be most appreciated.
Best Regards
I would like to use Vbscript to remove some files from folder. These files are log files created automatically by application daily, I only want to keep 14 days log files and remove rest of them.
Anyone can tell me how to write a VBScript for this purpose? I am quite a new person to VB script.
Any help would be most appreciated.
Best Regards
Eeek. Sorry i think I posed the wrong script above will search for folders in a directory and delete the old ones. I'll try to post the files one soon. If you don't here from me today then request this call to be delete refund and re-post. Once again sorry about that.
I very quickly fixed this one up and tested it try it out it should suit your need. this will delete files that have not been modified for 14 days.
Set Directory = Fso.GetFolder("C:\temp\tes t") ' place for directory details here
If DateDiff("D", Modified.DateLastModified, Now) > 14 Then Modified.Delete ' this line means 14 days
Set Directory = Fso.GetFolder("C:\temp\tes
If DateDiff("D", Modified.DateLastModified,
Dim Fso
Dim Directory
Dim Modified
Dim Files
Set Fso = CreateObject("Scripting.FileSystemObject")
Set Directory = Fso.GetFolder("C:\temp\test") ' place for directory details here
Set Files = Directory.Files
For Each Modified in Files
If DateDiff("D", Modified.DateLastModified, Now) > 14 Then Modified.Delete
Next
ASKER
Thanks Mass2612....
I will try it today and get it back to you ASAP.
Cheers
I will try it today and get it back to you ASAP.
Cheers
ASKER
Hi Mass2612
Your script is working perfectly. But I may need a small change. (I am sorry I didn't mention my question clearly. )
In my log folder, you can see the attachment in the below. I only want to remove log filename "access.2009-xx-xx" which is over 14 days. I want to keep file:boot, process, server, and all server.log.2009-xx-xx which could be over 14 days.
Could you please help me to change the script?
I appreciate to your help and time.
Cheers
logfile.JPG
Your script is working perfectly. But I may need a small change. (I am sorry I didn't mention my question clearly. )
In my log folder, you can see the attachment in the below. I only want to remove log filename "access.2009-xx-xx" which is over 14 days. I want to keep file:boot, process, server, and all server.log.2009-xx-xx which could be over 14 days.
Could you please help me to change the script?
I appreciate to your help and time.
Cheers
logfile.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Morning - did this end up working ok for you?
ASKER
Thanks for your help.
I have a script to cleanup log files on a particular directory for one of our apps. Maybe this will work for you. test it out and let us know if you have any ???
Lines you need to edit are: -
iDaysOld = 14
sDirPath = "D:\" ' drive letter of where the directory to clean up is
sDirName = "foldername" ' directory where the log files you need to cleanup are
Open in new window