

InterviewSolution
Saved Bookmarks
1. |
Solve : VB Scrript to delete old files and subfolders? |
Answer» HelloQuote from: gh0std0g74 on November 23, 2009, 06:11:40 PM I am only assuming Mike is Bill I think that is is a pretty safe asumption; "Mike" replicates "Bill"'s posting style to the letter. See his recent posts. Quote from: BatchFileBasics on November 23, 2009, 11:40:32 AM yuup bill is back. CAN SOMEONE PLEASE BAN HIM?! he is REALLY annoying me and disrupting all topics hes been inhe can just come in as another nick and do this stuff all over.Hey ike, How many members here do not like you?. you are up to about 15. including most high authority members. and the whole MS-Dos section. you doubt i can learn anything? i doubt anyone ACTUALLY wants you here. Quote from: Salmon Trout on November 24, 2009, 12:15:07 AM See his recent posts. Get a clue. Bill Richardson's name is at bottom of each post.Quote from: BatchFileBasics on November 24, 2009, 05:42:07 PM i doubt anyone actually wants you here.not me, i actually ENJOY browsing the forum when he's here. Please check both conditions that before date as well as whether it is empty or not. if it is empty meeans, just delete it. Please do it in the below coding If file.DateLastModified < BeforeDate and folder== null Then fso.DeleteFile(file.Path) please try to do. Dim fso, startFolder, OlderThanDate Set fso = CREATEOBJECT("Scripting.FileSystemObject" startFolder = "c:\test" OlderThanDate = DateAdd("d", -30, Date) ' 30 days DeleteOldFiles startFolder, OlderThanDate Function DeleteOldFiles(folderName, BeforeDate) Dim folder, file, fileCollection, folderCollection, subFolder Set folder = fso.GetFolder(folderName) Set fileCollection = folder.Files For Each file In fileCollection If file.DateLastModified < BeforeDate Then fso.DeleteFile(file.Path) End If Next Set folderCollection = folder.SubFolders For Each subFolder In folderCollection DeleteOldFiles subFolder.Path, BeforeDate Next End Function Function DeleteOldfolder(foldername, BeforeDate) Set folderlist = fso.GetFolder(foldername) Set folderCollection = Folderlist.SubFolders For Each Folder In folderCollection If folder.DateLastModified < BeforeDate Then fso.DeleteFolder(folder.Path) End If Next End Function Both conditions are checked, which is the purpose of the nested if. Code: [Select]Set f = fso.GetFolder(folderName) Set fc = f.Files If fc.Count = 0 Then If f.DateLastModified < BeforeDate Then fso.DeleteFolder foldername, True End If End If This function is unnecessary, there is not even a reference to it in the main script: Code: [Select]Function DeleteOldfolder(foldername, BeforeDate) Set folderlist = fso.GetFolder(foldername) Set folderCollection = Folderlist.SubFolders For Each Folder In folderCollection If folder.DateLastModified < BeforeDate Then fso.DeleteFolder(folder.Path) End If Next End Function Sheesh! |
|