Prev: Enumerate all printers installed at computer startup (With Startup GPO)
Next: IE8 installed, but script opens an IE6 browser
From: Gerard van on 28 May 2010 16:06 Hello the script works perfect, is it possible to make it so that different directory's can be checked ? I have about 15 directory's with differend archives were i want to use this script for. Already thanks, Gerard <D> wrote: I found this script one day when i was looking to do the same thing. 09-Nov-07 I found this script one day when i was looking to do the same thing. I made a few changes from the original such as coding in the location of the folder that held the subfolders, as well as autmoating it to detect folders/files longer than a specific number of days. Now, I used this in conjunction with a backup script I made, but the general functionality is the same. Just make sure to change the location of the folders, as well as the number of days it is compairing for. I have it set to 120 right now. it will also make/append a log file to tell you which folders it deleted. Might take some more changes to get it tweaked for your use, but here it is.. ' 'delete folders specified in a number of days, also specified in the script. ' On error resume next Dim Directory Dim Noofdays Dim FSO Dim FSO2 Dim LogFile Dim Folderlist Dim folders Directory ="\\server\share\folder\subfolder\" Noofdays=cint(120) LogFile="\\server\share\folder\subfolder\deleted.txt" Set FSO = CreateObject("Scripting.FileSystemObject") Set FSO2 = CreateObject("Scripting.FileSystemObject") Set oFSO = CreateObject("Scripting.FilesyStemObject") ' If oFSO.FileExists(Logfile) Then Const ForAppending = 8 Set ofile = oFSO.OpenTextFile(LogFile, ForAppending, True) Else Set oFile = oFSO.CreateTextFile(logfile, true) End If ofile.writeline "Delete Folders older than 120 days Started --> " & now() Set Folderlist = FSO.GetFolder(Directory) Set folders = Folderlist.SubFolders For Each d In Folders ' msgbox d.name ' msgbox d.size ' msgbox d.dateCreated ' msgbox d.dateLastModified ' msgbox d.dateLastAccessed tempdirectory = Directory & d.name If datediff("d",d.dateCreated,now()) > Noofdays Then FSO2.DeleteFolder(tempdirectory ) ofile.writeline "Deleting Folder...." & tempdirectory if err.number <>0 then ofile.writeline cstr(now()) & " " & Err.description err.clear end if End If Next ofile.writeline "Delete Folders older than 120 days Completed --> " &now() ofile.writeline "--------------------------------------------" ofile.close "cnknsd" <cnknsd(a)hotmail.com> wrote in message news:1194570591.922417.156470(a)k35g2000prh.googlegroups.com... Previous Posts In This Thread: On Thursday, November 08, 2007 8:09 PM cnknsd wrote: an easy script to delete folders on a network share that are older than 14 days I have read extensively regarding using VBSCRIPT to automate the deletion of files and folders locally and on network shares. Everything is so confusing, and I do not understand why... I got saddled with directory maintenance on of a share that is used to transfer data for upgrades. I need to make sure that no directories/ folders reside on the share that are older than 14 days. So I want to automate this task...Can someone provide me with a script that will delete all folders/directories on a share wether they are empty or not that are older than 14 days? I have found loads of examples for deleteing files that work great but I cannot get the folders to delete. Please Help! Here is an example of a script that is simple for files but I cannot figure out how to change it to delete folders instead of files. any help? Option Explicit on error resume next Dim oFSO Dim sDirectoryPath Dim oFolder Dim oFileCollection Dim oFile Dim iDaysOld 'Customize values here to fit your needs iDaysOld = 14 Set oFSO = CreateObject("Scripting.FileSystemObject") sDirectoryPath = "\\MyServer\MyFolder" set oFolder = oFSO.GetFolder(sDirectoryPath) set oFileCollection = oFolder.Files 'Walk through each file in this folder collection. 'If it is older than 2 weeks (14) days, then delete it. For each oFile in oFileCollection If oFile.DateLastModified < (Date() - iDaysOld) Then oFile.Delete(True) End If Next 'Clean up Set oFSO = Nothing Set oFolder = Nothing Set oFileCollection = Nothing Set oFile = Nothing On Friday, November 09, 2007 2:15 PM <D> wrote: I found this script one day when i was looking to do the same thing. I found this script one day when i was looking to do the same thing. I made a few changes from the original such as coding in the location of the folder that held the subfolders, as well as autmoating it to detect folders/files longer than a specific number of days. Now, I used this in conjunction with a backup script I made, but the general functionality is the same. Just make sure to change the location of the folders, as well as the number of days it is compairing for. I have it set to 120 right now. it will also make/append a log file to tell you which folders it deleted. Might take some more changes to get it tweaked for your use, but here it is.. ' 'delete folders specified in a number of days, also specified in the script. ' On error resume next Dim Directory Dim Noofdays Dim FSO Dim FSO2 Dim LogFile Dim Folderlist Dim folders Directory ="\\server\share\folder\subfolder\" Noofdays=cint(120) LogFile="\\server\share\folder\subfolder\deleted.txt" Set FSO = CreateObject("Scripting.FileSystemObject") Set FSO2 = CreateObject("Scripting.FileSystemObject") Set oFSO = CreateObject("Scripting.FilesyStemObject") ' If oFSO.FileExists(Logfile) Then Const ForAppending = 8 Set ofile = oFSO.OpenTextFile(LogFile, ForAppending, True) Else Set oFile = oFSO.CreateTextFile(logfile, true) End If ofile.writeline "Delete Folders older than 120 days Started --> " & now() Set Folderlist = FSO.GetFolder(Directory) Set folders = Folderlist.SubFolders For Each d In Folders ' msgbox d.name ' msgbox d.size ' msgbox d.dateCreated ' msgbox d.dateLastModified ' msgbox d.dateLastAccessed tempdirectory = Directory & d.name If datediff("d",d.dateCreated,now()) > Noofdays Then FSO2.DeleteFolder(tempdirectory ) ofile.writeline "Deleting Folder...." & tempdirectory if err.number <>0 then ofile.writeline cstr(now()) & " " & Err.description err.clear end if End If Next ofile.writeline "Delete Folders older than 120 days Completed --> " &now() ofile.writeline "--------------------------------------------" ofile.close "cnknsd" <cnknsd(a)hotmail.com> wrote in message news:1194570591.922417.156470(a)k35g2000prh.googlegroups.com... On Friday, November 09, 2007 2:58 PM cnknsd wrote: That is excelent..and in fact I can understand that script. That is excelent..and in fact I can understand that script. Thank you for posting that for me...You Rock! On Friday, November 09, 2007 4:27 PM cnknsd wrote: Ok, the script file works locally but it will not delete remotely, Iget Ok, the script file works locally but it will not delete remotely, I get permission denied error when I try to delete the folders on the server share. Does anyne have any suggestions? to resolve this? I do have full permissions to the share. On Monday, November 12, 2007 12:59 PM <D> wrote: I've not had a problem with the script running in our environment, be sure to I've not had a problem with the script running in our environment, be sure to check both your ntfs and your share permissions on the share that houses the files you're going to delete. Also, check the names of the files - you might have to make a modification if they include spaces in the name. fwitw. Doug "cnknsd" <cnknsd(a)hotmail.com> wrote in message news:1194643652.384091.34500(a)c30g2000hsa.googlegroups.com... On Monday, November 12, 2007 4:06 PM cnknsd wrote: I have had them checked and they are the way that they should, when Icheck I have had them checked and they are the way that they should, when I check what is actually running I find that the NT AUTHAURITY\Local Service is the operational entity. Does anyone know how to get the script to run under my credentials? On Thursday, November 15, 2007 8:55 AM <D> wrote: your credentials shouldn't be an issue if you have full control rights to the your credentials shouldn't be an issue if you have full control rights to the folder (both ntfs and share permissions). Another option would be that a program is running and currently using those folders (vscan, backup, etc???). Or, try this... make a set of folders on your drive, modify the script to point to those folders and maybe delete in 1 day instead of 40 or whatever. Then run the script against that set of folders to see if you are still having the issue. Chances are it will work just fine, in which case there's either something using those folders and therefore stopping you from deleting them, or you don't have the proper permissions. Do you have any 'special' permissions to those folders? Do they inherit the permissions from the parent folder? "cnknsd" <cnknsd(a)hotmail.com> wrote in message news:1194901616.435077.30450(a)v2g2000hsf.googlegroups.com... Submitted via EggHeadCafe - Software Developer Portal of Choice Free Online Courses Available for Eggheadcafe.com Users http://www.eggheadcafe.com/tutorials/aspnet/5261083e-6e03-4b25-8728-fc3cf6855293/free-online-courses-avail.aspx
From: Pegasus [MVP] on 28 May 2010 17:00
"Gerard van Heck" wrote in message news:201052816632gerardvanheck(a)hotmail.com... > Hello the script works perfect, is it possible to make it so that > different directory's can be checked ? I have about 15 directory's with > differend archives > were i want to use this script for. Already thanks, Gerard I recommend you start your own thread and do this: - Describe your requirements - Show us your script - Say where you have a problem |