Pacomp.vbs preserve the folder structure
-
Hi in pacomp.vbs by Micke how to preserve the folders structure of the files to compress.:confused: because just compress the files not the folder structure of each file.
thanks
'******************************************************************* '* PACOMP.vbs '* @author: Micke '* @hist 2010-02-26 CREATED:Script for compress multiple file types '* @hist 2010-03-01 BUGFIX: Space in path or filename resulted in '* no archive was created. '* '* Script for compress multiple file types '* '* Usage: cscript PACOMP.vbs ArchiveName.extension DrivePath '* Example1: cscript PACOMP.vbs C:\Temp\MyArchive.zip D: '* Example2: cscript PACOMP.vbs C:\Temp\MyArchive.zip D:\Temp '* '******************************************************************* Option Explicit 'Variables Dim FSO, objDir, aList, FileExtension, ArchiveName, DrivePath Dim aFile, aItem, strCompressionString, WshShell 'Constants (Change path to your own enviroment) Const PACOMP = "C:\Programs\PACL\PACOMP.exe" 'Check number of arguments If WScript.Arguments.Count <> 2 Then WScript.Echo "Usage: cscript PACOMP.vbs ArchiveName.extension DrivePath" WScript.Echo "Example 1: cscript PACOMP.vbs C:\Temp\MyArchive.zip D:" WScript.Echo "Example 2: cscript PACOMP.vbs C:\Temp\MyArchive.zip D:\Temp" 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) DrivePath = WScript.Arguments.Item(1) 'Get the Folders for the DrivePath Set objDir = FSO.GetFolder(DrivePath) 'Create a Array with Fileextensions for the archive, change to your enviroment aList = Array("png", "jpg", "avi") 'Search through the folders SearchFolders(objDir) 'Sub for Searching recursive in Folders Sub SearchFolders(pstrCurrentPath) For Each aFile In pstrCurrentPath.Files For Each FileExtension In aList If FileExtension = LCase(Right(CStr(aFile.Name), 3)) Then AddFileToArchive aFile.Path End If Next 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 " & Chr(34) & ArchiveName & Chr(34) & " " & Chr(34) & pstrFileName & Chr(34) WScript.Echo strCompressionString WshShell.Run strCompressionString, 0, True End Sub -
try logging to see what command is being sent to pacomp
-
Hi!
Sub AddFileToArchive(pstrFileName) 'Create the string with parameters for PACOMP strCompressionString = PACOMP & " -a -P " & Chr(34) & ArchiveName & Chr(34) & " " & Chr(34) & pstrFileName & Chr(34) WScript.Echo strCompressionString WshShell.Run strCompressionString, 0, True End Sub ```The command and the parameters sent to PACOMP will be displayed when you run the script. Look at this line in the script strCompressionString = PACOMP & " -a -P " & Chr(34) & ArchiveName & Chr(34) & " " & Chr(34) & **pstrFileName** & Chr(34) What's the value of **pstrFileName** when you run the script? Is it only the filename or is it the filename with the full path? Kind Regards Micke