Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8143685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:11:05+00:00 2026-06-06T13:11:05+00:00

I currently have a script that deletes old log files and then takes any

  • 0

I currently have a script that deletes old log files and then takes any files newer than the specified time frame and zips them up into a zip with the name of the localhost.zip.

What I am trying to do is just add the Date when the files were zipped appended onto the name of the zip.

So something ike localhost_Date.zip.

I know that I need to add something after “%computername%” but I am just not sure of the syntax to deal with it.

Thanks for any help in advance. Also if you see any improvements that could be made to my script just let me know. It’s pretty much just a beginners workings with tweaking other scripts found online to suit my needs.

Option Explicit

Dim oFSO, oFolder, sDirectoryPath 
Dim oFileCollection, oFile, sDir 
Dim iDaysOld 

' Specify Directory Path From Where You want to clear the old files 

sDirectoryPath = "C:\Testscripts\testfolder\"

' Specify Number of Days Old File to Delete

iDaysOld = 7

Set oFSO = CreateObject("Scripting.FileSystemObject") 
Set oFolder = oFSO.GetFolder(sDirectoryPath) 
Set oFileCollection = oFolder.Files 

For each oFile in oFileCollection

    'Specify the Extension of file that you want to delete 
    'and the number with Number of character in the file extension 



    If LCase(Right(Cstr(oFile.Name), 3)) = "log" Then

        If oFile.DateLastModified < (Date() - iDaysOld) Then 
        oFile.Delete(True) 
        End If 

    End If   
Next 



Set oFSO = Nothing 
Set oFolder = Nothing 
Set oFileCollection = Nothing 
Set oFile = Nothing 



WScript.Echo "Press to start zipping log files."

Dim objFile, objPath, objFolder, Command, PathLogs, RetVal
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell: Set objShell = CreateObject("WScript.Shell")

PathLogs = "C:\Testscripts\testfolder\" 'This path just has some test logs

' Loop through the logs and zip and move each file (if required, you could just move files with an '.log' extension)


Set objPath = objFSO.GetFolder(PathLogs)
For Each objFile In objPath.Files




    If (LCase(objfso.GetExtensionName(objFile)) = "log") Then

        ' zip files

        Command = """C:\Program Files\7-zip\7z.exe"" a " & PathLogs & "%computername%" & ".zip " & PathLogs & objFile.Name 

        RetVal = objShell.Run(Command,0,true)

    End If

Next

WScript.Echo "Zip Successful."

WScript.Echo "Now Moving Zipped Files into Archived Folder"

'move files

Set objFSO = CreateObject("Scripting.FilesystemObject")
objFSO.MoveFile "C:\Testscripts\testfolder\*.zip" , "C:\Testscripts\testfolder\Archived"

WScript.Echo "Move Successful."
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:11:06+00:00Added an answer on June 6, 2026 at 1:11 pm

    I skipped the gory details, sorry. Here is a two-line VBScript code to format current date as yyyy-mm-dd (keeping in mind that / is not allowed in filenames):

    Dim d : d = Date()
    Dim dateStr : dateStr = Year(d) & "-" & Right("00" & Month(d), 2) & "-" & Right("00" & Day(d), 2)
    
    ' Usage
    Command = """C:\Program Files\7-zip\7z.exe"" a " & PathLogs & "%computername%" & "-" & dateStr & ".zip " & PathLogs & objFile.Name
    

    Apart from that, this line:

    If LCase(Right(Cstr(oFile.Name), 3)) = "log" Then
    

    Can be written as using FSO.GetExtensionName:

    If LCase(oFSO.GetExtensionName(oFile.Name)) = "log" Then
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java Script function that takes an undefined time to finish. In
I currently have a script that scrapes proxies off websites, but I'm just wondering
Currently we have a script that does maven build + tomcat deploy. Deploying to
I currently have a python script that runs every few minutes and picks up
I currently have a Perl CGI script that parses incoming XML requests using XML::Simple
I have a batch script that calls a process and currently it waits for
I'm modifying a PHP script that I have and it is currently outputting a
I'm currently building my own login script and have noticed that most append the
I have a script that loops and adds markers one at a time. I
I have a SQL script that is being executed in TOAD. Currently, I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.