PowerArchiver Forums

PowerArchiver Forums (http://www.powerarchiver.com/forums/index.php)
-   Tech Support (http://www.powerarchiver.com/forums/forumdisplay.php?f=9)
-   -   [FIXED] Batch File to compress multiple file types (http://www.powerarchiver.com/forums/showthread.php?t=4460)

DHaralson 02-15-2010 11:56 AM

Batch File to compress multiple file types
 
I had an old batch file that used winzip that I am trying to convert over to use PACL.

What it should do
: Pulls all of the listed types of media files from a CD, including all subdirectories and preserving pathnames. Creates a .zip archive of all of them and outputs a log file.
The batch file takes 2 arguments: the name of the archive to create and the letter of the CD-Drive that has the CD in it.

When I run the Batch file as "makepzip ta0000 e" this is the output from the log:

Archive: d:\ta0000.zip
preparing to compress...
*** WARNING: Nothing to add or update...

All OK


So, it looks like either it is not going into all the subdirectories on the CD, or it is only checking the first filetype (jpg), because I know that there are .gif files in some of the directories.

Here are the commands in my Batch file:

@ECHO OFF
ECHO ** This batch file will find all Media Files on %2 and create a zip **
ECHO ** file called d:\%1.zip and d:\%1.log **
"c:\apps\PACOMP" -a -r -P d:\%1.zip %2:\*.jpg %2:\*.bmp %2:\*.gif %2:\*.jpeg %2:\*.tif
%2:\*.tiff %2:\*.mpg %2:\*.mpeg %2:\*.mov %2:\*.rm %2:\*.ram %2:\*.asf %2:\*.wmv %2:\*.mpe
%2:\*.avi %2:\*.jfif %2:\*.jif %2:\*.art %2:\*.jpe %2:\*.png %2:\*.vob %2:\*.3gp %2:\*.mpa
%2:\*.tmp %2:\*.3g2 %2:\*.asx %2:\*.flv %2:\*.shs %2:\*.m2v %2:\*.mod %2:\*.cjp %2:\*.divx
%2:\*.wm %2:\*.dv %2:\*.mp4 > d:\%1.log


Any help you can give me would be greatly appreciated. Thanks!

Dustin

TBGBe 02-15-2010 03:08 PM

Two thoughts - but not much help, I'm afraid.

a) I believe there is a 255 char limit on the command
b) It appears that the -r command does not work when a filetype is specified (i.e. works only with *.*)

Will have to wait for Spwolf or Milli to confirm / deny.

P.S. I did a quick test with PACL 6.01 on XP SP3

DHaralson 02-15-2010 03:20 PM

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.

DHaralson 02-16-2010 08:21 AM

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

DHaralson 02-16-2010 08:24 AM

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.

spwolf 02-16-2010 11:04 AM

didnt have time yet to look, will do a bit later on, thanks for the patience!

DHaralson 02-22-2010 09:53 AM

Hi spwolf, have you had a chance to look at this issue yet?

Thanks!

spwolf 02-22-2010 09:55 AM

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.

DHaralson 02-22-2010 09:57 AM

Hmm, ok, thanks!

Micke 02-26-2010 03:58 PM

1 Attachment(s)
Hi Dustin!

Quote:

Originally Posted by DHaralson (Post 21750)
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:
Code:

'***********************************************************
'* 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 Sub

You can also downloading the script here: Attachment 947

There are two lines in the script you have to modify for your own enviroment.

Change this to your path for PACOMP
Code:

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.
Code:

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

TBGBe 02-28-2010 09:00 AM

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 02-28-2010 11:14 AM

Quote:

Originally Posted by TBGBe (Post 21812)
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")

Quote:

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

Micke 02-28-2010 11:19 AM

Quote:

Originally Posted by TBGBe (Post 21812)
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

TBGBe 02-28-2010 05:24 PM

1 Attachment(s)
Quote:

Originally Posted by Micke (Post 21813)
Did you put a " around each fileextension in the Array? Like ("jpg", "png", "txt")

Quote:

Originally Posted by PACOMP.vbs
'Create a Array with Fileextensions for the archive, change to your enviroment
aList = Array("png", "jpg", "txt")

Quote:

Originally Posted by Micke (Post 21813)
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.zip

See 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 ??

Micke 03-01-2010 05:43 AM

1 Attachment(s)
Hi!

Quote:

Originally Posted by TBGBe (Post 21818)
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.

Code:

'*******************************************************************
'* 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

The updated script can be downloaded here: Attachment 949

Please let me know the result after you have tested the updated script.

Kind Regards
Micke

TBGBe 03-01-2010 01:11 PM

That's got it.

Well done :cool:

Micke 03-01-2010 01:41 PM

Thanks, nice to hear that it's working for you now.

Kind Regards
Micke

DHaralson 03-01-2010 02:07 PM

Wow, thanks for helping out with that script Micke! I'll give it a try.

Thanks,
Dustin

Micke 03-09-2010 03:28 AM

Hi Dustin!
Have you tested the script and if so, is it working correctly for you?

Kind Regards
Micke

DHaralson 03-09-2010 09:05 AM

Yes, your script works. Thanks for all the help!


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

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