PowerArchiver Home


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

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #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)
  #2  
Old 04-05-2010, 08:39 PM
moles42's Avatar
moles42 moles42 is offline
Alpha Tester
 
Join Date: Oct 2003
Location: Sydney - Australia
Posts: 856
Thanks: 45
Thanked 67 Times in 62 Posts
I haven't tested it personally but thanks 'Micke' for the great scripts.
__________________

Mike
+--------------------+
Windows 7 Ultimate x64
Intel Core 2 Duo E6850 3.00Ghz
nVidia GEForce 8600 GT
4.0 Gig Ram
+--------------------+

  #3  
Old 04-06-2010, 10:17 AM
TBGBe's Avatar
TBGBe TBGBe is offline
Still Mainly Lurking
 
Join Date: Jul 2001
Location: UK
Posts: 2,151
Thanks: 6
Thanked 102 Times in 94 Posts
Thanks Micke,
Seems to work fine.

Is there a way to specify year/month/day for date instead of day/month/year ?
__________________
Terry

WinXP SP3
  #4  
Old 04-06-2010, 12:20 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
Quote:
Originally Posted by TBGBe View Post
Thanks Micke,
Seems to work fine.

Is there a way to specify year/month/day for date instead of day/month/year ?
I don't know if that's possible, but I'll check that. I also found one annoying bug in the script, that I missed when I wrote it. I have assumed that the file extension always is 3 characters, but that won't work when you are working with 7-zip (7z) and zipx archives since they don't have a file extension of 3 characters. This resulted in a incorrect filename after adding date and time to it.

I need to do some more tests before I submit the updated script.

Kind Regards
Micke
  #5  
Old 04-06-2010, 03:08 PM
TBGBe's Avatar
TBGBe TBGBe is offline
Still Mainly Lurking
 
Join Date: Jul 2001
Location: UK
Posts: 2,151
Thanks: 6
Thanked 102 Times in 94 Posts
Yeah. I was just about to report that "test.tar.gz" doesn't work.
I guess you know why
__________________
Terry

WinXP SP3
  #6  
Old 04-06-2010, 04:39 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
Hi!
I think it's working correctly now. I have also update the date parameter. You can now select from different date format.

Here's the updated script
Code:
'***********************************************************************
'* PACOMP_DT.vbs
'* @author: Micke
'* @hist 2010-04-05	CREATED:Script for adding Date and Time to Filename
'* @hist 2010-04-06 BUGFIX: Assumed the file extension always contains
'*							3 character, resulting in incorrect
'*							Filename when using a file extension with
'*							other than 3 characters.
'* @hist 2010-04-06	UPDATE:	Added support for different dateformat
'*
'* The script requires 4 parameters
'* Usage: cscript PACOMP_DT.vbs <param1> <param2> <param3> <param4>
'*
'* param1: 	-d1 = Add current date (YYYYMMDD) to filename
'*			-d2 = Add current date (DDMMYYYY) to filename
'*			-d3 = Add current date (MMDDYYYY) to filename
'*			-d = Works the same as -d1
'* 			-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, bCheck

'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: -d1 = Add current date (YYYYMMDD) to filename"
	WScript.Echo "param1: -d2 = Add current date (DDMMYYYY) to filename"
	WScript.Echo "param1: -d3 = Add current date (MMDDYYYY) to filename"
	WScript.Echo "param1: -d = Works the same as -d1"
	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 CheckDTParameter() = True Then
	UpdateArchiveName()
	RunPACOMP()
Else
	WScript.Echo "Parameter 1 incorrect"
	WScript.Echo "Value set as: " & strDT_Parameter
	WScript.Echo "Expected value would be: -t, -d, -d1, -d2,-d3, -dt, -d1t, -d2t, -d3t"
	WScript.Echo "Exit the script"
	WScript.Quit
End If

Sub UpdateArchiveName()
	
	'Get the ArchiveName from the path
	strOnlyArchiveName = Mid(strArchiveNamePath, InStrRev(strArchiveNamePath, "\")+1)
	
	'Get the ArchiveExtension
	strArchiveExtension = Mid(strArchiveNamePath, InStrRev(strArchiveNamePath, ".")+1)
		
	'Get the ArchiveName without extension
	strOnlyArchiveNameNoExtension = Left(strOnlyArchiveName, Len(strOnlyArchiveName)-Len(strArchiveExtension)-1)
	
	'Get the Path without the ArchiveName
	strPath = Left(strArchiveNamePath,Len(strArchiveNamePath)-Len(strOnlyArchiveName))
		
	'Insert Date and Time to the ArchiveName
	If strDT_Parameter = "-d" Or strDT_Parameter = "-d1" Or strDT_Parameter = "-d2" Or strDT_Parameter = "-d3" 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

Function FormatNumbers(n, totalDigits)
 
	If totalDigits > Len(n) Then
		FormatNumbers = String(totalDigits-Len(n),"0") & n 
    Else 
        FormatNumbers = n 
   	End If
   	 
End Function

Function CheckDTParameter()

	Select Case strDT_Parameter
		Case "-d" 'YYYYMMDD
			bCheck = True
			strDate = Year(Date()) & FormatNumbers(Month(Date()),2) & FormatNumbers(Day(Date()),2)
		Case "-d1" 'YYYYMMDD
			bCheck = True
			strDate = Year(Date()) & FormatNumbers(Month(Date()),2) & FormatNumbers(Day(Date()),2)
		Case "-d2" 'DDMMYYYY
			bCheck = True
			strDate = FormatNumbers(Day(Date()),2) & FormatNumbers(Month(Date()),2) & Year(Date())
		Case "-d3" 'MMDDYYYY
			bCheck = True
			strDate = FormatNumbers(Month(Date()),2) & FormatNumbers(Day(Date()),2) & Year(Date())
		Case "-t" 'HHMMSS
			bCheck = True
			GetFormattedTime()
		Case "-dt" 'YYYYMMDD HHMMSS
			bCheck = True
			strDate = Year(Date()) & FormatNumbers(Month(Date()),2) & FormatNumbers(Day(Date()),2)
			GetFormattedTime()
		Case "-d1t" 'YYYYMMDD HHMMSS
			bCheck = True
			strDate = Year(Date()) & FormatNumbers(Month(Date()),2) & FormatNumbers(Day(Date()),2)
			GetFormattedTime()
		Case "-d2t" 'DDMMYYYY HHMMSS
			bCheck = True
			strDate = FormatNumbers(Day(Date()),2) & FormatNumbers(Month(Date()),2) & Year(Date())
			GetFormattedTime()
		Case "-d3t" 'MMDDYYYY HHMMSS
			bCheck = True
			strDate = FormatNumbers(Month(Date()),2) & FormatNumbers(Day(Date()),2) & Year(Date())
			GetFormattedTime()
		Case Else
			bCheck = False
	End Select
	
	CheckDTParameter = bCheck
	
End Function

Sub GetFormattedTime()
	
	'Clear unwanted characters from the date and time
	Set objRegEx = CreateObject("VBScript.RegExp")
	objRegEx.Global = True
	objRegEx.Pattern = "[^0-9]"
	
	'Find out current time
	strTime = FormatDateTime(Time(), vbLongTime)
		
	'Clear unwanted characters from the date and time
	strTime = objRegEx.Replace(strTime, "")
	
End Sub
The script requires 4 parameters to work properly.

Parameter 1
Can be "-d", "-d1", "-d2", "-d3", "-t", "-dt", "-d1t", "-d2t", "-d3t"
-d = Add current date (YYYYMMDD) to the ArchiveName
-d1 = Add current date (YYYYMMDD) to the ArchiveName
-d2 = Add current date (DDMMYYYY) to the ArchiveName
-d3 = Add current date (MMDDYYYY) 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\*.*
cscript PACOMP_DT.vbs -d2t -a C:\Temp\MyArchive.zip D:\*.doc
I hope everything is working correctly now.

Kind Regards
Micke
  #7  
Old 04-07-2010, 11:45 AM
TBGBe's Avatar
TBGBe TBGBe is offline
Still Mainly Lurking
 
Join Date: Jul 2001
Location: UK
Posts: 2,151
Thanks: 6
Thanked 102 Times in 94 Posts
Sorry, still fails with name2.tar.gz or name2.tar.bz2

Could it be the "doubled extension" (two dots) causing problems with
Quote:
'Get the ArchiveExtension
strArchiveExtension = Mid(strArchiveNamePath, InStrRev(strArchiveNamePath, ".")+1)
__________________
Terry

WinXP SP3
  #8  
Old 04-07-2010, 12:49 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
Quote:
Originally Posted by TBGBe View Post
Sorry, still fails with name2.tar.gz or name2.tar.bz2

Could it be the "doubled extension" (two dots) causing problems with
Well, it's working as expected for me. name2.tar.gz will have the fileextension "gz" and the new filename will be name2.tar_YYYYMMDD_HHMMSS.gz

I assume you want the date and time appear before the first dot, which would be like name2_YYYYMMDD_HHMMSS.tar.gz

Is that correct?

Kind Regards
Micke
  #9  
Old 04-07-2010, 01:03 PM
TBGBe's Avatar
TBGBe TBGBe is offline
Still Mainly Lurking
 
Join Date: Jul 2001
Location: UK
Posts: 2,151
Thanks: 6
Thanked 102 Times in 94 Posts
Quote:
Originally Posted by Micke View Post
Well, it's working as expected for me. name2.tar.gz will have the fileextension "gz" and the new filename will be name2.tar_YYYYMMDD_HHMMSS.gz
Yes, but PACOMP cannot create the archive as it needs "tar.gz / tar.bz2 " to perform the compression

Quote:
Originally Posted by Micke View Post
I assume you want the date and time appear before the first dot, which would be like name2_YYYYMMDD_HHMMSS.tar.gz

Is that correct?

Kind Regards
Micke
Yes - well at least before the archive type control extension (don't know if there might be something like
"create.this.archive.for.me.tar.gz" which works in PACL!! )

However, this is getting too complicated.
I would be happy just to PREFIX the archive name with time/date to give
YYYYMMDD_HHMMSS_name2.tar.gz
which I guess is much simpler (and clarifies why I asked for YEAR/Month/Day format).
__________________
Terry

WinXP SP3
The Following User Says Thank You to TBGBe For This Useful Post:
spwolf (04-09-2010)
  #10  
Old 04-07-2010, 01:42 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
Quote:
Originally Posted by TBGBe View Post
Yes, but PACOMP cannot create the archive as it needs "tar.gz / tar.bz2 " to perform the compression
Ok, then the date and time must be placed before the first dot in the filename

Quote:
Originally Posted by TBGBe View Post
However, this is getting too complicated. I would be happy just to PREFIX the archive name with time/date to give
YYYYMMDD_HHMMSS_name2.tar.gz
which I guess is much simpler (and clarifies why I asked for YEAR/Month/Day format).
It's not that complicated, the problem here is to know all the rules for the fileextension used in PACL before writning the script. I was assuming that we would have filename.extension in all archives.

It's much simpler to add the date and time in the beginning of the filename. The reason for adding it between the name and the extension is that it will be easier when you list the archives in explorer and they begin with their original filename and the date and time is inside it.

I'll fix this by adding the date and time before the first dot in the filename instead of the last dot.

Kind Regards
Micke
  #11  
Old 04-07-2010, 02:59 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
Hi TBGBe!

Quote:
Originally Posted by TBGBe View Post
Yes, but PACOMP cannot create the archive as it needs "tar.gz / tar.bz2 " to perform the compression
I have tested this and both creation and extraction of archive work with filename like Test1.tar_20100407_213915.bz2 or Test2.tar_20100407_213915.gz

Code:
C:\Programs\PACL>pacomp -a Test1.tar_20100407_213915.bz2 *.txt

Archive: C:\Programs\PACL\Test1.tar_20100407_213915.bz2
  preparing to compress...
  adding: filelist.txt   --> Done. [0%]
  adding: filelist2.txt   --> Done. [0%]
  adding: LICENSE.TXT   --> Done. [22%]
  adding: MANUAL.TXT   --> Done. [59%]
  adding: ORDER.TXT   --> Done. [62%]
  adding: README.TXT   --> Done. [77%]
  adding: WHATSNEW.TXT   --> Done. [100%]
  BZIPing... please wait...

All OK

C:\Programs\PACL>
Code:
C:\Programs\PACL>paext -e -pc:\Programs\Temp Test1.tar_20100407_213915.bz2
Archive --> C:\Programs\PACL\Test1.tar_20100407_213915.bz2 [BZIPed TAR]

  extracting: filelist.txt   --> Done. [0%]
  extracting: filelist2.txt   --> Done. [0%]
  extracting: LICENSE.TXT   --> Done. [22%]
  extracting: MANUAL.TXT   --> Done. [59%]
  extracting: ORDER.TXT   --> Done. [62%]
  extracting: README.TXT   --> Done. [77%]
  extracting: WHATSNEW.TXT   --> Done. [100%]

C:\Programs\PACL>
Code:
C:\Programs\PACL>pacomp -a Test2.tar_20100407_213915.gz *.txt
Archive: C:\Programs\PACL\Test2.tar_20100407_213915.gz
  preparing to compress...
  adding: filelist.txt   --> Done. [0%]
  adding: filelist2.txt   --> Done. [0%]
  adding: LICENSE.TXT   --> Done. [22%]
  adding: MANUAL.TXT   --> Done. [59%]
  adding: ORDER.TXT   --> Done. [62%]
  adding: README.TXT   --> Done. [77%]
  adding: WHATSNEW.TXT   --> Done. [100%]
  GZIPing... please wait...

All OK

C:\Programs\PACL>
Code:
C:\Programs\PACL>paext -e -pc:\Programs\Temp Test2.tar_20100407_213915.gz
Archive --> C:\Programs\PACL\Test2.tar_20100407_213915.gz [GZIPed TAR]

  extracting: filelist.txt   --> Done. [0%]
  extracting: filelist2.txt   --> Done. [0%]
  extracting: LICENSE.TXT   --> Done. [22%]
  extracting: MANUAL.TXT   --> Done. [59%]
  extracting: ORDER.TXT   --> Done. [62%]
  extracting: README.TXT   --> Done. [77%]
  extracting: WHATSNEW.TXT   --> Done. [100%]

C:\Programs\PACL>
Maybe I have missed something here but it seems to work properly for me.

Kind Regards
Micke
  #12  
Old 04-08-2010, 06:03 AM
TBGBe's Avatar
TBGBe TBGBe is offline
Still Mainly Lurking
 
Join Date: Jul 2001
Location: UK
Posts: 2,151
Thanks: 6
Thanked 102 Times in 94 Posts
Hmm, perhaps I'm missing something then - I get this when running the script
Attached Images
 
__________________
Terry

WinXP SP3
  #13  
Old 04-08-2010, 11:33 AM
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
Quote:
Originally Posted by TBGBe View Post
Hmm, perhaps I'm missing something then - I get this when running the script
Hmm, I can see one thing that could get this error. In the script there's one constant
Code:
Const PACOMP = "C:\Programs\PACL\PACOMP.exe"
You are in C:\PACL when you are running the script and the commandline starts with "C:\Programs\PACL\PACOMP.exe", but are you sure you have PACL installed in that folder? I know I haven't comment the script about that you have to change this line, because the constant is the same as I have used in previous scripts.

Kind Regards
Micke
  #14  
Old 04-08-2010, 01:56 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
Hi!
Here's the updated script. Now the date and time always is placed before the first dot in the filename, like this.

MyArchive_YYYYMMDD_HHMMSS.properties.txt.tar.bz2

I have also put a check if PACOMP.exe exists in the specified path of the constant. If not, a message will tell you about it and the script will exit.

Code:
'***********************************************************************
'* PACOMP_DT.vbs
'* @author: Micke
'* @hist 2010-04-05	CREATED:Script for adding Date and Time to Filename
'* @hist 2010-04-06 BUGFIX: Assumed the file extension always contains
'*							3 character, resulting in incorrect
'*							Filename when using a file extension with
'*							other than 3 characters.
'* @hist 2010-04-06	UPDATE:	Added support for different dateformat
'* @hist 2010-04-08 UPDATE:	Added check for existing PACOMP in the
'*							specified path
'* @hist 2010-04-08 UPDATE:	Moved date and time to be placed before
'*							the first dot in the filename
'*
'* The script requires 4 parameters
'* Usage: cscript PACOMP_DT.vbs <param1> <param2> <param3> <param4>
'*
'* param1: 	-d1 = Add current date (YYYYMMDD) to filename
'*			-d2 = Add current date (DDMMYYYY) to filename
'*			-d3 = Add current date (MMDDYYYY) to filename
'*			-d = Works the same as -d1
'* 			-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, bCheck

'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: -d1 = Add current date (YYYYMMDD) to filename"
	WScript.Echo "param1: -d2 = Add current date (DDMMYYYY) to filename"
	WScript.Echo "param1: -d3 = Add current date (MMDDYYYY) to filename"
	WScript.Echo "param1: -d = Works the same as -d1"
	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 that PACOMP exists in the specified path
If FSO.FileExists(PACOMP) Then
	WScript.Echo "PACOMP.exe found, ok to continue the script"
Else
	WScript.Echo "PACOMP.exe could not be found in the specified path"
	WScript.Echo "The path is set to: " & PACOMP
	WScript.Echo "Update the constant PACOMP to contain a valid path"
	WScript.Echo "Exit the script"
	WScript.Quit
End If

'Check the parameter for Date and Time
If CheckDTParameter() = True Then
	UpdateArchiveName()
	RunPACOMP()
Else
	WScript.Echo "Parameter 1 incorrect"
	WScript.Echo "Value set as: " & strDT_Parameter
	WScript.Echo "Expected value would be: -t, -d, -d1, -d2,-d3, -dt, -d1t, -d2t, -d3t"
	WScript.Echo "Exit the script"
	WScript.Quit
End If

Sub UpdateArchiveName()
	
	'Get the ArchiveName from the path
	strOnlyArchiveName = Mid(strArchiveNamePath, InStrRev(strArchiveNamePath, "\")+1)
	
	'Get the ArchiveExtension
	strArchiveExtension = Mid(strArchiveNamePath, InStr(strArchiveNamePath, ".")+1)
		
	'Get the ArchiveName without extension
	strOnlyArchiveNameNoExtension = Left(strOnlyArchiveName, Len(strOnlyArchiveName)-Len(strArchiveExtension)-1)
	
	'Get the Path without the ArchiveName
	strPath = Left(strArchiveNamePath,Len(strArchiveNamePath)-Len(strOnlyArchiveName))
		
	'Insert Date and Time to the ArchiveName
	If strDT_Parameter = "-d" Or strDT_Parameter = "-d1" Or strDT_Parameter = "-d2" Or strDT_Parameter = "-d3" 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

Function FormatNumbers(n, totalDigits)
 
	If totalDigits > Len(n) Then
		FormatNumbers = String(totalDigits-Len(n),"0") & n 
    Else 
        FormatNumbers = n 
   	End If
   	 
End Function

Function CheckDTParameter()

	Select Case strDT_Parameter
		Case "-d" 'YYYYMMDD
			bCheck = True
			strDate = Year(Date()) & FormatNumbers(Month(Date()),2) & FormatNumbers(Day(Date()),2)
		Case "-d1" 'YYYYMMDD
			bCheck = True
			strDate = Year(Date()) & FormatNumbers(Month(Date()),2) & FormatNumbers(Day(Date()),2)
		Case "-d2" 'DDMMYYYY
			bCheck = True
			strDate = FormatNumbers(Day(Date()),2) & FormatNumbers(Month(Date()),2) & Year(Date())
		Case "-d3" 'MMDDYYYY
			bCheck = True
			strDate = FormatNumbers(Month(Date()),2) & FormatNumbers(Day(Date()),2) & Year(Date())
		Case "-t" 'HHMMSS
			bCheck = True
			GetFormattedTime()
		Case "-dt" 'YYYYMMDD HHMMSS
			bCheck = True
			strDate = Year(Date()) & FormatNumbers(Month(Date()),2) & FormatNumbers(Day(Date()),2)
			GetFormattedTime()
		Case "-d1t" 'YYYYMMDD HHMMSS
			bCheck = True
			strDate = Year(Date()) & FormatNumbers(Month(Date()),2) & FormatNumbers(Day(Date()),2)
			GetFormattedTime()
		Case "-d2t" 'DDMMYYYY HHMMSS
			bCheck = True
			strDate = FormatNumbers(Day(Date()),2) & FormatNumbers(Month(Date()),2) & Year(Date())
			GetFormattedTime()
		Case "-d3t" 'MMDDYYYY HHMMSS
			bCheck = True
			strDate = FormatNumbers(Month(Date()),2) & FormatNumbers(Day(Date()),2) & Year(Date())
			GetFormattedTime()
		Case Else
			bCheck = False
	End Select
	
	CheckDTParameter = bCheck
	
End Function

Sub GetFormattedTime()
	
	'Clear unwanted characters from the date and time
	Set objRegEx = CreateObject("VBScript.RegExp")
	objRegEx.Global = True
	objRegEx.Pattern = "[^0-9]"
	
	'Find out current time
	strTime = FormatDateTime(Time(), vbLongTime)
		
	'Clear unwanted characters from the date and time
	strTime = objRegEx.Replace(strTime, "")
	
End Sub
Kind Regards
Micke
  #15  
Old 04-08-2010, 02:59 PM
TBGBe's Avatar
TBGBe TBGBe is offline
Still Mainly Lurking
 
Join Date: Jul 2001
Location: UK
Posts: 2,151
Thanks: 6
Thanked 102 Times in 94 Posts
Thumbs up

Quote:
Originally Posted by Micke View Post
Hmm, I can see one thing that could get this error. In the script there's one constant
Code:
Const PACOMP = "C:\Programs\PACL\PACOMP.exe"
You are in C:\PACL when you are running the script
Blush

However, when I remembered to change it, I still have a problem opening the archive using PowerArchiver (not PACL) as it doesn't handle the tar file because of the date text.

Quote:
Originally Posted by Micke;
Here's the updated script.
OK this works well for me now - thanks a lot.
__________________
Terry

WinXP SP3
  #16  
Old 04-08-2010, 03:15 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
Quote:
Originally Posted by TBGBe View Post
OK this works well for me now - thanks a lot.
No problem, however it was a little more job to get it running the way I wanted than I expected in the beginning.

I suspect the next script will be much more complicated than this one. I haven't sorted out yet how to solve all the problems in it, but it will be a different way of using PACL to create archives.

Kind Regards
Micke
  #17  
Old 04-08-2010, 04:08 PM
TBGBe's Avatar
TBGBe TBGBe is offline
Still Mainly Lurking
 
Join Date: Jul 2001
Location: UK
Posts: 2,151
Thanks: 6
Thanked 102 Times in 94 Posts
Quote:
Originally Posted by Micke View Post
... it will be a different way of using PACL to create archives.
A GUI perhaps
__________________
Terry

WinXP SP3
  #18  
Old 04-09-2010, 01:14 AM
guido's Avatar
guido guido is offline
Alpha tester x
 
Join Date: Jun 2001
Location: The netherlands
Posts: 1,841
Thanks: 0
Thanked 71 Times in 67 Posts
see http://www.autoitscript.com/autoit3/index.shtml for a simple GUI builder. it's perfect for a wrapper around a command line tool
__________________
Windows 7 x64 (NLD/ENG), I5-760
  #19  
Old 04-09-2010, 12:33 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
I have no plans for a GUI, as PA already has a very good and powerful GUI. I also want to thank TBGBe for taking time to test the script. Without your help I wouldn't find the problem with extensions like tar.gz and tar.bz2.

I haven't written the next upcoming script yet, but I have some ideas of what it should be able to do. You will see it when it's ready for test.

Kind Regards
Micke
The Following User Says Thank You to Micke For This Useful Post:
spwolf (04-09-2010)
  #20  
Old 04-09-2010, 03:04 PM
TBGBe's Avatar
TBGBe TBGBe is offline
Still Mainly Lurking
 
Join Date: Jul 2001
Location: UK
Posts: 2,151
Thanks: 6
Thanked 102 Times in 94 Posts
Quote:
Originally Posted by Micke View Post
I have no plans for a GUI ...
That was meant to be a joke - not sure if Guido knew it.

P.S. Welcome back Guido
__________________
Terry

WinXP SP3
  #21  
Old 04-09-2010, 06:07 PM
guido's Avatar
guido guido is offline
Alpha tester x
 
Join Date: Jun 2001
Location: The netherlands
Posts: 1,841
Thanks: 0
Thanked 71 Times in 67 Posts
I was never gone. I was always watching you guys big brother style. I just had nothing interesting to report. :-)
__________________
Windows 7 x64 (NLD/ENG), I5-760
Closed Thread

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:39 AM.


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