View Single Post
  #13  
Old 03-12-2010, 03:36 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 Badders!
Here's a script for use with PACL 6.01. It will solve half of your problem by making it possible to have more than one row in a list file.

I have made it very simple for me, the script assumes that you have a maximum of 10 rows in the list file. It's very easy to add more if you need to.

Here's the code for the script. Copy the code and save it as PACOMP_List.vbs or whatever name you prefer.

Code:
'******************************************************************************
'* PACOMP_List.vbs
'* @author:	Micke
'* @hist	2010-03-12	CREATED:Script for compress multiple file types
'*						using a listfile.
'*
'* Usage: cscript PACOMP_List.vbs ArchiveName.extension ListFilePath
'* Example1: cscript PACOMP_List.vbs C:\Temp\MyArchive.zip C:\Temp\ListFile.txt
'* Example2: cscript PACOMP_List.vbs C:\Temp\MyArchive.zip D:\Test\FileLists.txt
'*
'*******************************************************************************
Option Explicit

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

'Variables
Dim FSO, objDir, aList(10), aPath(10), FileExtension, ArchiveName, ListFilePath
Dim aFile, aItem, strCompressionString, WshShell, objTextFile
Dim strCurrentLine, iCounter, strPath, DrivePath, strCurrentFileName

'Check number of arguments
If WScript.Arguments.Count <> 2 Then
	WScript.Echo "Usage: cscript PACOMP_List.vbs ArchiveName.extension ListFilePath"
	WScript.Echo "Example 1: cscript PACOMP_List.vbs C:\Temp\MyArchive.zip C:\Temp\ListFile.txt"
	WScript.Echo "Example 2: cscript PACOMP_List.vbs C:\Temp\MyArchive.zip D:\Test\FileLists.txt"
	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
ArchiveName = WScript.Arguments.Item(0)
ListFilePath = WScript.Arguments.Item(1)

'Read data from ListFile
If FSO.FileExists(ListFilePath) Then
	ReadFromListFile()
Else
	WScript.Echo "Could not find ListFile"
	WScript.Echo "Path to ListFile set as: " & ListFilePath
	WScript.Echo "Unable to continue script, exiting..."
	WScript.Quit
End If

'Check the filetypes in the ListFile
CheckFileTypes()

Sub ReadFromListFile()

	iCounter = 0

	Set objTextFile = FSO.OpenTextFile(ListFilePath, 1)

	Do Until objTextFile.AtEndOfStream
		aPath(iCounter)= objTextFile.ReadLine
		iCounter = iCounter + 1
	Loop
	
	objTextFile.Close
	
End Sub


Sub CheckFileTypes()
	
	'Check the Array of FilePaths
	For Each strPath In aPath
		
		If Len(strPath) > 0 Then
			
			'Get the FileName from the path
			strCurrentFileName = Mid(strPath, InStrRev(strPath, "\")+1)
			
			'Check if FileName is not set as *.*
			If strCurrentFileName <> "*.*" Then
			
				'Get the Path without the FileName
				strPath = Left(strPath,Len(strPath)-Len(strCurrentFileName))
				
				'Get the FileExtension
				FileExtension = LCase(Right(strCurrentFileName, 3))
				
				'Set the current folder to start searching from
				Set objDir = FSO.GetFolder(strPath)
				SearchFolders(objDir)
			Else
				AddAllFilesToArchive(strPath)
			End If
		End If
		
	Next

End Sub

'Sub for Searching recursive in Folders
Sub SearchFolders(pstrCurrentPath)
	
	For Each aFile In pstrCurrentPath.Files
		If FileExtension = LCase(Right(CStr(aFile.Name), 3)) Then
			AddFileToArchive aFile.Path
		End If
	Next
	
	For Each aItem In pstrCurrentPath.SubFolders
	   SearchFolders(aItem)
	Next

End Sub

Sub AddFileToArchive(pstrFileName)
	
	'Create the string with parameters for PACOMP
	strCompressionString = PACOMP & " -a -p -k -c2 " & Chr(34) & ArchiveName & Chr(34) & " " & Chr(34) & pstrFileName & Chr(34)
	WScript.Echo strCompressionString
	WshShell.Run strCompressionString, 0, True
	
End Sub

Sub AddAllFilesToArchive(pstrFileName)

	'Create the string with parameters for PACOMP
	strCompressionString = PACOMP & " -a -r -p -k -c2 " & Chr(34) & ArchiveName & Chr(34) & " " & Chr(34) & pstrFileName & Chr(34)
	WScript.Echo strCompressionString
	WshShell.Run strCompressionString, 0, True

End Sub
I don't know if you have any use of this. I only wrote it because it's fun writing scripts as workarounds for problems

The script is only tested with PACL 6.01 on Windows XP Sp3.

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