Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: VB Scrript to delete old files and subfolders  (Read 10334 times)

0 Members and 1 Guest are viewing this topic.

MikeTaylor



    Rookie

    Re: VB Scrript to delete old files and subfolders
    « Reply #15 on: November 23, 2009, 06:55:03 PM »
    Hello
    « Last Edit: November 24, 2009, 06:10:21 PM by MikeTaylor »
    Bill Richardson

    Salmon Trout

    • Guest
    Re: VB Scrript to delete old files and subfolders
    « Reply #16 on: November 24, 2009, 12:15:07 AM »
    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.

    gh0std0g74



      Apprentice

      Thanked: 37
      Re: VB Scrript to delete old files and subfolders
      « Reply #17 on: November 24, 2009, 01:41:02 AM »
      yuup bill is back. CAN SOMEONE PLEASE BAN HIM?! he is really annoying me and disrupting all topics hes been in
      he can just come in as another nick and do this stuff all over.

      BatchFileBasics



        Hopeful

        Thanked: 18
        Re: VB Scrript to delete old files and subfolders
        « Reply #18 on: November 24, 2009, 05:42:07 PM »
        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.

        When the power of love overcomes the love of power the world will know peace - Jimi Hendrix.

        MikeTaylor



          Rookie

          Re: VB Scrript to delete old files and subfolders
          « Reply #19 on: November 24, 2009, 06:12:22 PM »
          See his recent posts.


          Get a clue.

          Bill Richardson's  name is at bottom of each post.
          Bill Richardson

          gh0std0g74



            Apprentice

            Thanked: 37
            Re: VB Scrript to delete old files and subfolders
            « Reply #20 on: November 24, 2009, 07:12:02 PM »
            i doubt anyone actually wants you here.
            not me, i actually enjoy browsing the forum when he's here. :)

            menaha



              Newbie

              Re: VB Scrript to delete old files and subfolders
              « Reply #21 on: November 25, 2009, 02:44:44 AM »
              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

              Sidewinder



                Guru

                Thanked: 139
              • Experience: Familiar
              • OS: Windows 10
              Re: VB Scrript to delete old files and subfolders
              « Reply #22 on: November 25, 2009, 06:58:55 AM »
              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!  8)
              The true sign of intelligence is not knowledge but imagination.

              -- Albert Einstein