Announcement

Collapse
No announcement yet.

VBS. NOW this one is REALLY hard....

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBS. NOW this one is REALLY hard....

    hi all

    really struggling with this script im working on right now.

    Its is essentially to Archive log files whih must be retained.
    Ive dealt with several aspects and areas of my script which is in VBS.

    Basically a .ZIP folder is created (i have this bit working ok)
    that folder is named after the date...

    NOW what i need to do..

    I need to move all .old and .log files from which are older than 15 days in to the newly ceated .ZIP folder.

    However this needs to be completed inside 58 different folders
    (58 different sets of logs to be zipped up)

    This process wil then be repeated over every day but if there are no file older than 15 days to archive they will not get added to any .ZIP folder and that .ZIP folder will then get deleted. (i have this part too sorted out.

    Cheers

    Paul

  • #2
    Re: VBS. NOW this one is REALLY hard....

    You could iterate through folders via a foreach loop and pick the desired files.

    For more complete an advice, please provide a mock-up about the directory structure and file names. Does the system work so that all old enough files in folder_1 are to be archived together? Or are you hoping to get just a single archive that contains all the old files?

    -P

    Comment


    • #3
      Re: VBS. NOW this one is REALLY hard....

      Originally posted by vonPryz View Post
      You could iterate through folders via a foreach loop and pick the desired files.

      For more complete an advice, please provide a mock-up about the directory structure and file names. Does the system work so that all old enough files in folder_1 are to be archived together? Or are you hoping to get just a single archive that contains all the old files?

      -P
      Hi there thanks for your reply,
      Sorry im pretty new at scripting so please bear with me.


      Sure let me explain the folder structure. (im sure you will get the idea.)

      The folder (ZIP Archive) is a standard windows folder.
      The folder (06-11-09) is a standard windows .ZIP folder

      UK (Within this folder are the .LOG and .OLD to be moved)
      (ZIP Archive) created by .VBS
      (06-11-09) created by .VBS
      (07-11-09) created by .VBS
      (08-11-09) created by .VBS

      France (Within this folder are the .LOG and .OLD to be moved)
      (Zip Archive) created by .VBS
      (06-11-09) created by .VBS
      (07-11-09) created by .VBS
      (08-11-09) created by .VBS

      USA (Within this folder are the .LOG and .OLD to be moved)
      (ZIP Archive) created by .VBS
      (06-11-09) created by .VBS
      (07-11-09) created by .VBS
      (08-11-09) created by .VBS

      GER (Within this folder are the .LOG and .OLD to be moved)
      (ZIP Archive) created by .VBS
      (06-11-09) created by .VBS
      (07-11-09) created by .VBS
      (08-11-09) created by .VBS

      AUS (Within this folder are the .LOG and .OLD to be moved)
      (ZIP Archive) created by .VBS
      (06-11-09) created by .VBS
      (07-11-09) created by .VBS
      (08-11-09) created by .VBS

      CHI (Within this folder are the .LOG and .OLD to be moved)
      (ZIP Archive) created by .VBS
      (06-11-09) created by .VBS
      (07-11-09) created by .VBS
      (08-11-09) created by .VBS

      NOR (Within this folder are the .LOG and .OLD to be moved)
      (ZIP Archive) created by .VBS
      (06-11-09) created by .VBS
      (07-11-09) created by .VBS
      (08-11-09) created by .VBS

      We have so many log files and they are used so often they must be broken up.

      The best way i can see of doing this while still leaving them "findable" is to move all .LOG and .OLD files greater than 15 days old in to a .ZIP file.

      The script will continue to run in the background and when there are more .LOGs and .OLDS move them in to that days "DATE"".zip folder.

      Cheers all
      Paul

      Full code is attached.
      Attached Files

      Comment


      • #4
        Re: VBS. NOW this one is REALLY hard....

        Are all the 58 different folders (etc UK, FRANCE, USA) within 1 folder ("C:\robo\logs")?

        If so, you can do something similar to this to move the files (change the code in blue to reflect moving the files, instead of deleting):

        Code:
        ' the path to the folder where all the sub folders are
        Path = "C:\robo\logs"
        
        ' the file extensions that you would like to move
        strFileType1 ="log"
        strFileType2 ="old"
        
        ' this is where you define how old you want the files to be before you move them
        Movedate = Date() - 15
        
        ' create an arrary to gather the filenames
        arFiles = Array()
        
        ' create the object
        Set FSO = CreateObject("Scripting.FileSystemObject")
        
        ' initiate the sub
        SelectFiles Path, Movedate, arFiles, True
        
        ' start nMoved at 0, this is just a counter
        ' to determine how many files have moved
        ' its not really needed, just validation if you want it
        nMoved = 0
        
        ' define the zip folder
        strZipPath = folder_path & "\Zip Archive"
        
        ' create a for statement to go through the arrary
        ' ubound means the total count for the arrary
        ' so its really for n=0 to 15, or however many files the array counts
        For n = 0 to ubound(arFiles)
        On Error Resume Next
        
          ' here is where you will put code to move the files
          ' I updated it to move the files into the zipfolder for you =)
          arFiles(n).Move strZipPath
        
          ' if there is an error, do nothing
          If Err.Number <> 0 Then
          
          ' if there is no error, add 1 to nMoved
          Else
            nMoved = nMoved + 1
          End If
           On Error Goto 0
        Next
        
        WScript.Quit(0)
        
        
        Sub SelectFiles(sPath,vMoveDate,arFilesToMove,bIncludeSubFolders)
          On Error Resume Next
        
          Set Folder = FSO.GetFolder(sPath)
          Set Files = Folder.Files
         
          For Each File in Files
          
           ' only select extensions log OR old
           If FSO.GetExtensionName(File.Name) = strFileType1 OR strFileType2 Then
        
            dtLastModified = Null
            On Error Resume Next
            
            ' get the date last modified for the current file
            dtLastModified = File.DateLastModified
            On Error Goto 0
            If Not IsNull(dtLastModified) Then
              
              ' if the last modified date is greater than the Movedate,
              ' then add the file to the arrary
              If dtLastModified < vMoveDate Then
                Count = ubound(arFilesToMove) + 1
                Redim Preserve arFilesToMove(Count)
                Set arFilesToMove(Count) = File
              End If
            End If
           End If
          Next
         
          ' if there are subfolders, 
          ' then restart the sub all over again for the subfolder
          If bIncludeSubFolders Then
            For Each fldr in Folder.Subfolders
              SelectFiles fldr.Path,vMoveDate,arFilesToMove,True
            Next
          End If
        End sub
        Last edited by ekrengel; 9th November 2009, 22:17.

        Comment


        • #5
          Re: VBS. NOW this one is REALLY hard....

          Hi there

          Thanks a million for your reply

          Sorry this is so far above me. I dont understand what you have posted.
          Could you breifly explain what it will be doing please..?

          And re the bit in blue you outline what are my options..??

          just treat me like a idiot on this one please..!

          PAul
          Attached Files
          Last edited by paul.killington; 6th November 2009, 22:43.

          Comment


          • #6
            Re: VBS. NOW this one is REALLY hard....

            Hi there

            Sorry have been unable to effect any changes here are you able to advise at all..?

            Kr

            Paul



            Originally posted by ekrengel View Post
            Are all the 58 different folders (etc UK, FRANCE, USA) within 1 folder ("C:\robo\logs")?

            If so, you can do something similar to this to move the files (change the code in blue to reflect moving the files, instead of deleting):

            Code:
            Path = "C:\robo\logs"
            strFileType1 ="log"
            strFileType2 ="old"
             
            Movedate = Date() - 15
             
            arFiles = Array()
            Set FSO = CreateObject("Scripting.FileSystemObject")
             
            SelectFiles Path, Movedate, arFiles, True
             
            nMoved = 0
            For n = 0 to ubound(arFiles)
            On Error Resume Next 
             'arFiles(n).Delete True
             If Err.Number <> 0 Then
             Else
               nMoved = nMoved + 1
             End If
              On Error Goto 0
            Next
             
            WScript.Quit(0)
             
            Sub SelectFiles(sPath,vMoveDate,arFilesToMove,bIncludeSubFolders)
              On Error Resume Next
             
              Set Folder = FSO.GetFolder(sPath)
              Set Files = Folder.Files
             
              For Each File in Files
             
               If FSO.GetExtensionName(File.Name) = strFileType1 OR strFileType2 Then
             
                dtLastModified = Null
                On Error Resume Next
                dtLastModified = File.DateLastModified
                On Error Goto 0
                If Not IsNull(dtLastModified) Then
                  If dtLastModified < vMoveDate Then
                    Count = ubound(arFilesToMove) + 1
                    Redim Preserve arFilesToMove(Count)
                    Set arFilesToMove(Count) = File
                  End If
                End If
               End If
              Next
             
              If bIncludeSubFolders Then
                For Each fldr in Folder.Subfolders
                  SelectFiles fldr.Path,vMoveDate,arFilesToMove,True
                Next
              End If
            End sub

            Comment


            • #7
              Re: VBS. NOW this one is REALLY hard....

              Originally posted by paul.killington View Post
              Hi there

              Thanks a million for your reply

              Sorry this is so far above me. I dont understand what you have posted.
              Could you breifly explain what it will be doing please..?

              And re the bit in blue you outline what are my options..??

              just treat me like a idiot on this one please..!

              PAul
              I updated my post, and added comments into the code that should help you understand better. I also added the option to move the files.

              Do you need help putting it all together? Or was it just an explanation that you needed?

              Comment


              • #8
                Re: VBS. NOW this one is REALLY hard....

                Originally posted by ekrengel View Post
                I updated my post, and added comments into the code that should help you understand better. I also added the option to move the files.

                Do you need help putting it all together? Or was it just an explanation that you needed?
                Hi there thats great thanks,

                Can you help me acheive the final goal of the script as ive got 18 GB of .LOGs to get archived..! And im under strict instructions to keep them all.

                (Here im using Just Norway as an example of course there are other countrys.)

                NOR (Within this folder are the .LOG and .OLD to be moved)

                (ZIP Archive) created by .VBS

                (06-11-09) created by .VBS
                (07-11-09) created by .VBS
                (08-11-09) created by .VBS

                Here is where i am at now.

                Folder Norway gets created by annother script, in there are dumped all of norways .LOG files.

                Now ive a script which will Create a folder named Zip Archive beneath every country, it will then create a ZIP file named after the current date beneath that.

                From what I understand your script will move the files in to the folder ZIP archive. Though i still cant get it working yet, no error is generated.

                BUT what really needs to happen is for them to get moved in to the ZIP folder named after the current date (which was just created) if they are older than 15 days.

                Ive been looking on the web for ages this is way above me and i cant find anything dynamic enough to do the job.

                Hope this is relativly clear..!
                All your help is really appreaciated

                Paul

                Comment


                • #9
                  Re: VBS. NOW this one is REALLY hard....

                  Hi there

                  Ive modified your code a little (so it creates a subfolder which would be the .zip folder in the finished version).
                  After this i need to get someway for it it to identify each folder so in this line;
                  strFolder = "C:\test" & "\Zip Archive\" & tdyday & "-" & tdyDate & "-" & tdyYear
                  The "c:\test" needs to call multiple locations..!

                  Thing is i still cant actually get it to move any files.


                  'the path to the folder where all the sub folders are
                  Path = "C:\robo\logs"
                  ' the file extensions that you would like to move
                  strFileType1 ="log"
                  'strFileType2 ="old"
                  ' this is where you define how old you want the files to be before you move them
                  Movedate = Date() - 10
                  ' create an arrary to gather the filenames
                  arFiles = Array()
                  ' create the object
                  Set FSO = CreateObject("Scripting.FileSystemObject")
                  ' initiate the sub
                  SelectFiles Path, Movedate, arFiles, True
                  ' start nMoved at 0, this is just a counter
                  ' to determine how many files have moved
                  ' its not really needed, just validation if you want it
                  nMoved = 0
                  ' define the zip folder
                  Dim tdyDate,tdyYear,tdyMonthName,tdyDay,strZipData
                  tdyDay= Day (Now)
                  tdyDate=Month(Now)
                  tdyYear=Year(Now)

                  strFolder = "C:\test" & "\Zip Archive\" & tdyday & "-" & tdyDate & "-" & tdyYear
                  set objFSO = createobject("Scripting.FileSystemObject")
                  if objFSO.FolderExists(strFolder) = False then
                  objFSO.CreateFolder strFolder
                  else
                  wscript.echo "Folder already exists"
                  end if

                  strZipPath = "C:\test" & "\Zip Archive\" & tdyDay & "-" & tdyDate & "-" & tdyYear
                  MsgBox(strzippath)


                  ' create a for statement to go through the arrary
                  ' ubound means the total count for the arrary
                  ' so its really for n=0 to 15, or however many files the array counts
                  For n = 0 to ubound(arFiles)
                  On Error Resume Next
                  ' here is where you will put code to move the files
                  ' I updated it to move the files into the zipfolder for you =)
                  arFiles(n).Move
                  'MsgBox(strZipPath)
                  ' if there is an error, do nothing
                  If Err.Number <> 0 Then

                  ' if there is no error, add 1 to nMoved
                  Else
                  nMoved = nMoved + 1
                  End If
                  On Error Goto 0
                  Next
                  WScript.Quit(0)
                  Sub SelectFiles(sPath,vMoveDate,arFilesToMove,bInclude SubFolders)
                  On Error Resume Next
                  Set Folder = FSO.GetFolder(sPath)
                  Set Files = Folder.Files
                  'MsgBox(StrPath)
                  For Each File in Files

                  ' only select extensions log OR old
                  If FSO.GetExtensionName(File.Name) = strFileType1 OR strFileType2 Then
                  dtLastModified = Null
                  On Error Resume Next

                  'MsgBox(StrPath)
                  ' get the date last modified for the current file
                  dtLastModified = File.DateLastModified
                  On Error Goto 0
                  If Not IsNull(dtLastModified) Then

                  ' if the last modified date is greater than the Movedate,
                  ' then add the file to the arrary
                  If dtLastModified < vMoveDate Then
                  Count = ubound(arFilesToMove) + 1
                  Redim Preserve arFilesToMove(Count)
                  Set arFilesToMove(Count) = File
                  End If
                  End If
                  End If
                  Next

                  ' if there are subfolders,
                  ' then restart the sub all over again for the subfolder
                  If bIncludeSubFolders Then
                  For Each fldr in Folder.Subfolders
                  SelectFiles fldr.Path,vMoveDate,arFilesToMove,True
                  Next
                  End If
                  End sub

                  Comment

                  Working...
                  X