PowerArchiver Home


Go Back   PowerArchiver Forums > PowerArchiver Command Line (PACL) > Tech Support

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 04-05-2010, 05:48 PM
Micke's Avatar
Micke Micke is offline
PA Super User
 
Join Date: Feb 2010
Location: Sweden
Posts: 131
Thanks: 11
Thanked 52 Times in 40 Posts
Automatic add date and time to Archivename

Hi!
I read in this thread a question about how to add date and time to a new archives filename when using PACL.

Well, PACL have support for this, with a little help of this script of course

Here's the code for the script
Code:
'***********************************************************************
'* PACOMP_DT.vbs
'* @author: Micke
'* @hist 2010-04-05	CREATED:Script for adding Date and Time to Filename
'* 
'* The script requires 4 parameters
'* Usage: cscript PACOMP_DT.vbs <param1> <param2> <param3> <param4>
'*
'* param1: 	-d = Add current date to filename
'* 			-t = Add current time to filename
'*			-dt = Add current date and time to filename
'*
'* param2:	The commands PACOMP uses
'* param3:	Filename of the Archive with extension
'* param4:	Path to file(s) and/or directory
'*
'* Add date and time to Archivename MyArchive.zip
'* Example: cscript PACOMP_DT.vbs -dt -a C:\Temp\MyArchive.zip D:\*.doc
'*
'***********************************************************************
Option Explicit

'Variables
Dim FSO, WshShell, objRegEx, strDate, strDT_Parameter, strArchiveExtension
Dim strTime, strArchiveNamePath, strPACOMP_Commands, strFileName
Dim strOnlyArchiveName, strPath, strOnlyArchiveNameNoExtension
Dim strCompressionString

'Constants
Const PACOMP = "C:\Programs\PACL\PACOMP.exe"

'Check number of arguments
If WScript.Arguments.Count <> 4 Then
	WScript.Echo "Usage: cscript PACOMP_DT.vbs <param1> <param2> <param3> <param4>"
	WScript.Echo "param1: -d = Add current date to filename"
	WScript.Echo "param1: -t = Add current time to filename"
	WScript.Echo "param1: -dt = Add current date and time to filename"
	WScript.Echo "param2: The commands PACOMP uses"
	WScript.Echo "param3: Filename of the Archive with extension"
	WScript.Echo "param4: Path to file(s) and/or directory"
	WScript.Echo "Example: cscript PACOMP_DT.vbs -dt -a C:\Temp\MyArchive.zip D:\*.doc"
	WScript.Echo "Will add date and time to Archivename MyArchive.zip"
	WScript.Quit
End If

'Create the FileSystemObject
Set FSO = CreateObject("Scripting.FileSystemObject")

'Create the ShellObject
Set WshShell = CreateObject("WScript.Shell")

'Get data from the Arguments
strDT_Parameter = WScript.Arguments.Item(0)
strPACOMP_Commands = WScript.Arguments.Item(1)
strArchiveNamePath = WScript.Arguments.Item(2)
strFileName = WScript.Arguments.Item(3)

'Check the parameter for Date and Time
If strDT_Parameter = "-d" Or strDT_Parameter = "-t" Or strDT_Parameter = "-dt" Then
	WScript.Echo "ArchiveName before adding date and time: " & strArchiveNamePath
	UpdateArchiveName()
	WScript.Echo "ArchiveName after adding date and time: " & strArchiveNamePath
	RunPACOMP()
Else
	WScript.Echo "Parameter 1 incorrect"
	WScript.Echo "Value set as: " & strDT_Parameter
	WScript.Echo "Expected value would be: -t or -d or -dt"
	WScript.Echo "Exit the script"
	WScript.Quit
End If

Sub UpdateArchiveName()

	GetFormattedDateTime()
	
	'Get the ArchiveName from the path
	strOnlyArchiveName = Mid(strArchiveNamePath, InStrRev(strArchiveNamePath, "\")+1)
	
	'Get the ArchiveName without extension
	strOnlyArchiveNameNoExtension = Left(strOnlyArchiveName, Len(strOnlyArchiveName)-4)
	
	'Get the Path without the ArchiveName
	strPath = Left(strArchiveNamePath,Len(strArchiveNamePath)-Len(strOnlyArchiveName))
	
	'Get the ArchiveExtension
	strArchiveExtension = Mid(strArchiveNamePath, InStrRev(strArchiveNamePath, ".")+1)
	
	'Insert Date and Time to the ArchiveName
	If strDT_Parameter = "-d" Then
		strOnlyArchiveName = strOnlyArchiveNameNoExtension & "_" & strDate & "." & strArchiveExtension
	ElseIf strDT_Parameter = "-t" Then
		strOnlyArchiveName = strOnlyArchiveNameNoExtension & "_" & strTime & "." & strArchiveExtension
	Else
		strOnlyArchiveName = strOnlyArchiveNameNoExtension & "_" & strDate & "_" & strTime & "." & strArchiveExtension
	End If
	
	strArchiveNamePath = strPath & strOnlyArchiveName
	
End Sub

Sub RunPACOMP()

	'Create the string with parameters for PACOMP
	strCompressionString = PACOMP & " " & strPACOMP_Commands & " " & Chr(34) & strArchiveNamePath & Chr(34) & " " & Chr(34) & strFileName & Chr(34)
	WScript.Echo strCompressionString
	WshShell.Run strCompressionString, 0, True

End Sub

Sub GetFormattedDateTime()

	'Clear unwanted characters from the date and time
	Set objRegEx = CreateObject("VBScript.RegExp")
	objRegEx.Global = True
	objRegEx.Pattern = "[^0-9]"
	
	'Find out current date and time
	strDate = FormatDateTime(Date(), vbGeneralDate)
	strTime = FormatDateTime(Time(), vbLongTime)
		
	'Clear unwanted characters from the date and time
	strDate = objRegEx.Replace(strDate, "")
	strTime = objRegEx.Replace(strTime, "")

End Sub
The script requires 4 parameters to work properly.

Parameter 1
Can be "-d", "-t" or "-dt"
-d = Add current date to the ArchiveName
-t = Add current time to the ArchiveName
-dt = Add current date and time to the ArchiveName

Parameter 2
The commands PACOMP uses. Note: The script doesn't check if the commands are valid for PACOMP, it only check that this parameter exists. Also note: If you have more than one command in this parameter {-a -p}, you have to put quotes around these {"-a -p"}, otherwise you'll get an error as the script will take each command for a separate parameter.

Parameter 3
Filename of the Archive with extension

Parameter 4
Files to add to the Archive

Example
Code:
cscript PACOMP_DT.vbs -dt -a C:\Temp\MyArchive.zip D:\*.doc
cscript PACOMP_DT.vbs -dt "-a -P" C:\Temp\MyArchiveTest.zip D:\Temp\*.*
I have tested this on Swedish WinXP Sp3 with PACL 6.01. Please let me know if you find bugs in the script. However, since the script is only used for automatic add date and/or time to the Archivename I haven't put that many error control in the script.

Kind Regards
Micke
The Following User Says Thank You to Micke For This Useful Post:
spwolf (04-09-2010)
 

Bookmarks

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatic wiping Socrates Wishlist 0 10-16-2009 08:49 AM
BUG: PACOMP.EXE Modifying Date/Time of Compressed Files in ZIP gsbell Tech Support 4 11-13-2008 04:38 PM
How to auto set archive date/time? barefoot General 2 06-27-2006 02:55 PM
Set archive time and date to latest in file By-Tor Wishlist 1 05-05-2006 04:04 AM


All times are GMT -5. The time now is 12:33 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.