HELP PLEASE!!!! Script VBS

Author Message
abizanda

  • Total Posts : 4
  • Scores: 0
  • Reward points : 0
  • Joined: 11/6/2011
  • Status: offline
HELP PLEASE!!!! Script VBS Monday, November 07, 2011 12:01 AM (permalink)
0
Hi all,

Im having problems with a script.

Im trying to create a script that check if date of folders in a path are older than 30 days and delete them.

But the hard part is that i need to check in a second level, for example:

C:\path\folder1\folder2

The folder i wanna check is folder2 and in the same level of folder 1 exists more folders.

I add my code and please if u can help this scripting Noob :(((

Option Explicit
Dim objSistema
Dim objCarpeta
Dim objDirectorio
Dim Fecha_Antiguedad
Dim Ruta
Ruta = "c:\Example"
Fecha_Antiguedad = DateAdd("d",-30, Date )
Set objSistema = CreateObject("Scripting.FileSystemObject")
Set objCarpeta = objSistema.GetFolder(Ruta)
For Each objDirectorio In objCarpeta.SubFolders
If DateValue(objDirectorio.DateCreated) <= DateValue(Fecha_Antiguedad) Then

objDirectorio.Delete
End If
Next
Set objDirectorio = Nothing
Set objCarpeta = Nothing
Set objSistema = Nothing

THANKS IN ADVANCE!
<message edited by abizanda on Monday, November 07, 2011 12:05 AM>
 
#1
    59cobalt

    • Total Posts : 969
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:HELP PLEASE!!!! Script VBS Monday, November 07, 2011 11:59 AM (permalink)
    0
    Do you want to check if C:\path\folder1\folder2 is older than 30 days? Then you don't need a loop at all. Or do you want to check if the subfolders of C:\path\folder1\folder2 are older than 30 days? If you only want to check the first level of subfolders, you simply set the variable Ruta to "C:\path\folder1\folder2".

    For further advice you need to supply more details about your requirements.

    BTW, .DateCreate already is of type Date, so it's pointless to convert it to type Date.
     
    #2
      rajpes

      • Total Posts : 3
      • Scores: 0
      • Reward points : 0
      • Joined: 6/7/2011
      • Status: offline
      Re:HELP PLEASE!!!! Script VBS Monday, November 07, 2011 6:21 PM (permalink)
      0
      Ruta="C:\path\folder1"
       
      #3
        abizanda

        • Total Posts : 4
        • Scores: 0
        • Reward points : 0
        • Joined: 11/6/2011
        • Status: offline
        Re:HELP PLEASE!!!! Script VBS Monday, November 07, 2011 6:36 PM (permalink)
        0
        Thanks for the answers first of all.
         
        Yes, i want to check if C:\path\folder1\folder2 is older than 30 days but the question is that i only wanna check this second level and in the first level exists more folders but that i cannot delete, for example:
         
        C:\path\folder1a_cannot_delete\folder2a_wanna_delete
        C:\path\folder1a_cannot_delete\folder2b_wanna_delete
        C:\path\folder1a_cannot_delete\folder2c_wanna_delete
        C:\path\folder1a_cannot_delete\folder2d_wanna_delete
        C:\path\folder1b_cannot_delete\folder2a_wanna_delete
        C:\path\folder1b_cannot_delete\folder2b_wanna_delete
        C:\path\folder1c_cannot_delete\folder2_wanna_delete
        C:\path\folder1d_cannot_delete\folder2a_wanna_delete
        C:\path\folder1d_cannot_delete\folder2b_wanna_delete
        C:\path\folder1e_cannot_delete\folder2
         
        There is an app that creates a lot of folders (in level folder1) as a projects, and after creates a second level of directories to throw the logs (folder2) im interested to check the age of ONLY the level 2, because i only wanna delete the logs not the project's folder.
         
        Sorry 4 my english ...
         
        THANKS ANOTHER TIME IN ADVANCE!!!
         
        #4
          59cobalt

          • Total Posts : 969
          • Scores: 91
          • Reward points : 0
          • Joined: 7/17/2011
          • Status: offline
          Re:HELP PLEASE!!!! Script VBS Tuesday, November 08, 2011 10:46 AM (permalink)
          0
          Since you already know the full path to the folder, it's as simple as:
          Ruta = "C:\path\folder1\folder2"
          Set objSistema = CreateObject("Scripting.FileSystemObject")
          Set objCarpeta = objSistema.GetFolder(Ruta)
          If objCarpeta.DateCreated <= (Date - 30) Then objCarpeta.Delete True

           
          #5
            abizanda

            • Total Posts : 4
            • Scores: 0
            • Reward points : 0
            • Joined: 11/6/2011
            • Status: offline
            Re:HELP PLEASE!!!! Script VBS Tuesday, November 08, 2011 8:40 PM (permalink)
            0
            Thanks but this is not valid, cause as I said in the other reply exists a lot of folder i wanna check. Not only the path u said.
             
            The app creates folders with the date en level2 (folder2) with the date, u understand? But also creates folders in level 1 (folder1) but this ones dont wanna to check cause i dont need to delete.
             
            Thanks
             
            #6
              59cobalt

              • Total Posts : 969
              • Scores: 91
              • Reward points : 0
              • Joined: 7/17/2011
              • Status: offline
              Re:HELP PLEASE!!!! Script VBS Wednesday, November 09, 2011 7:49 AM (permalink)
              0
              Sorry, my misunderstanding. So you have a root folder C:\path and want to check all subfolders if their (2nd level) subfolders are older than 30 days? For that you need two loops:
              Ruta = "C:\path"
              Fecha_Antiguedad = Date - 30
              Set objSistema = CreateObject("Scripting.FileSystemObject")
              Set objCarpeta = objSistema.GetFolder(Ruta)
              For Each sf1 In objCarpeta.SubFolders
               For Each sf2 In sf1.SubFolders
               If sf2.DateCreated <= Fecha_Antiguedad Then sf2.Delete True
               Next
              Next

               
              #7
                abizanda

                • Total Posts : 4
                • Scores: 0
                • Reward points : 0
                • Joined: 11/6/2011
                • Status: offline
                Re:HELP PLEASE!!!! Script VBS Wednesday, November 16, 2011 1:38 AM (permalink)
                0
                Works perfect!!!!!
                 
                Thanks 4 all ur help!
                 
                #8
                  59cobalt

                  • Total Posts : 969
                  • Scores: 91
                  • Reward points : 0
                  • Joined: 7/17/2011
                  • Status: offline
                  Re:HELP PLEASE!!!! Script VBS Wednesday, November 16, 2011 9:19 AM (permalink)
                  0
                  De nada.
                   
                  #9

                    Online Bookmarks Sharing: Share/Bookmark

                    Jump to:

                    Current active users

                    There are 0 members and 1 guests.

                    Icon Legend and Permission

                    • New Messages
                    • No New Messages
                    • Hot Topic w/ New Messages
                    • Hot Topic w/o New Messages
                    • Locked w/ New Messages
                    • Locked w/o New Messages
                    • Read Message
                    • Post New Thread
                    • Reply to message
                    • Post New Poll
                    • Submit Vote
                    • Post reward post
                    • Delete my own posts
                    • Delete my own threads
                    • Rate post

                    2000-2012 ASPPlayground.NET Forum Version 3.9