Note that there are some explanatory texts on larger screens.

plurals
  1. POVBscript adding date to name of zip file
    text
    copied!<p>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.</p> <p>What I am trying to do is just add the Date when the files were zipped appended onto the name of the zip.</p> <p>So something ike localhost_Date.zip.</p> <p>I know that I need to add something after "%computername%" but I am just not sure of the syntax to deal with it. </p> <p>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. </p> <pre><code>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 &lt; (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 " &amp; PathLogs &amp; "%computername%" &amp; ".zip " &amp; PathLogs &amp; 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." </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload