Batch File to compress multiple file types
-
Hmm, didn’t think about the character limit, although it does get all the way through the command and create the log file. I am using 6.01 with WinXP SP3 as well.
I guess I could execute a separate command to add each file type to the archive, but I was hoping there was a more efficient way of doing it.
-
I did some more testing, using multiple instances of the command, can definitely say that it is not recursing the subdirectories. Anyone see a syntax error in the command I’m using?
“c:\apps\PACOMP” -a -r -P d:%1.zip %2:*.inf >> d:%1.log
-
Guess I should add that passing in the arguments and using them in the commands is working fine. There was a .inf file in the root, and it successfully added it to the archive and sent the log to the file.
-
didnt have time yet to look, will do a bit later on, thanks for the patience!
-
Hi spwolf, have you had a chance to look at this issue yet?
Thanks!
-
i have an feeling recurse subfolder option does not work unless it gets ., which is where the problem would be then… i have sent it to dev team to investigate.
-
Hmm, ok, thanks!
-
Hi Dustin!
Any help you can give me would be greatly appreciated. Thanks!
Dustin
You can get the function you are looking for by using a small vbscript that will loop through the folders looking for the specified fileextensions. This is a workaround for the problem that filename like *.jpg won’t work when using the recursive parameter.
The script is this:
'*********************************************************** '* PACOMP.vbs '* @author: Micke '* '* Script for compress multiple file types '* '* Usage: cscript PACOMP.vbs ArhiveName.extension DrivePath '* Example1: cscript PACOMP.vbs MyArchive.zip D: '* Example2: cscript PACOMP.vbs 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 MyArchive.zip D:" WScript.Echo "Example 2: cscript PACOMP.vbs 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 " & ArchiveName & " " & pstrFileName WScript.Echo strCompressionString WshShell.Run strCompressionString, 0, True End SubYou can also downloading the script here:
There are two lines in the script you have to modify for your own enviroment.
Change this to your path for PACOMP
Const PACOMP = "C:\Programs\PACL\PACOMP.exe"Add more FileExtension for your Archive. I have tested it with these 3 and it works as expected.
aList = Array("png", "jpg", "avi")The script is only tested on Windows XP with SP3. Hope that it will work for you.
Kind Regards
Micke
attachment_p_21800_0_pacomp_script.zip -
Micke,
When I tried it -I changed the path to PACOMP and the extension array to (jpg, png, txt).
Each “expected” command line was echoed, but no archive file was created :confused:
Then I tried full path ( c:\multypes.zip ) for “my archive” but other than that my script understanding is very limited.
What did I miss?
-
Micke,
When I tried it -I changed the path to PACOMP and the extension array to (jpg, png, txt).
Did you put a " around each fileextension in the Array? Like (“jpg”, “png”, “txt”)
Each “expected” command line was echoed, but no archive file was created :confused:
Then I tried full path ( c:\multypes.zip ) for “my archive” but other than that my script understanding is very limited.
What did I miss?
How is your command written in the CMD Window when you are running the script? If I can see your command I can then see if something is missing.
Kind Regards
Micke -
Then I tried full path ( c:\multypes.zip ) for “my archive” but other than that my script understanding is very limited.
What did I miss?
There could be a privilege problem. If you are logged on as a non administrator user in Windows XP, you don’t have write access to the root of c:\
Try to change the archive name from c:\multypes.zip to c:\temp\multypes.zip
Kind Regards
Micke -
Did you put a " around each fileextension in the Array? Like (“jpg”, “png”, “txt”)
@PACOMP.vbs:
'Create a Array with Fileextensions for the archive, change to your enviroment
aList = Array(“png”, “jpg”, “txt”)How is your command written in the CMD Window when you are running the script? If I can see your command I can then see if something is missing.
…
Try to change the archive name from c:\multypes.zip to c:\temp\multypes.zipSee attached screenshot
The c:\temp folder is empty.
Thanks for getting back so quick.P.S. I am admin on WinXP SP3
P.P.S. Just thought - should the output path/filename to add be in quotes ??

-
Hi!
P.P.S. Just thought - should the output path/filename to add be in quotes ??
That’s correct. I have made some more tests and the problem appears when you have spaces in the path and/or in the filename. That’s my mistake :o, because when I tested the script I didn’t have any spaces in the path or in the filename resulting in that everything looked ok.
Here’s the updated script with support for spaces in path or filename.
'******************************************************************* '* 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 SubThe updated script can be downloaded here:
Please let me know the result after you have tested the updated script.
Kind Regards
Micke
attachment_p_21823_0_pacomp_script_updated.zip -
That’s got it.
Well done :cool:
-
Thanks, nice to hear that it’s working for you now.
Kind Regards
Micke -
Wow, thanks for helping out with that script Micke! I’ll give it a try.
Thanks,
Dustin -
Hi Dustin!
Have you tested the script and if so, is it working correctly for you?Kind Regards
Micke -
Yes, your script works. Thanks for all the help!
