Solved

batch files to automate "Compressed (Zipped) Folder" tasks

Posted on 2007-03-24
9
4,407 Views
Last Modified: 2009-01-15
I am running Windows XP, and frequently use the feature "send to Compressed (Zipped) Folder" to move big files.

Is there a way to write batch files to automate compressing and extracting these files?

Thanks
0
Comment
Question by:hpsuser
  • 4
  • 3
9 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18785068
Not "those" files...you can use a vbscript to do that.
For a pure batch file, you'd need to grab the command-line versions of pkzip, and pkunzip...
0
 
LVL 12

Expert Comment

by:RubenvdLinden
ID: 18791390
I really like the command-line version of PowerArchiver (PACL), which can be found at http://www.powerarchiver.com/
It comes with a small manual to help you understand all the different commands and parameters, the exit codes (for batch file errorlevel codes) and some examples.

I hope this helps.
0
 

Author Comment

by:hpsuser
ID: 18796633
So it sounds like I'd have to use a different tool then what we're currently using?
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 67

Expert Comment

by:sirbounty
ID: 18796705
Unless you want to script the process (send to compressed folder) using vbscript...I have some sample code, if you're interested...
0
 

Author Comment

by:hpsuser
ID: 18796950
I've never used vbscript, though if it's easy to implement and all I'd need to do is change the directories or files names I can give it a try...Thanks
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 125 total points
ID: 18804282
This is what I'm using...this will recursively compress the .log files in the strPath folder...there may be some 'bugs' (which will error), since I typed this over (couldn't get my mail working at the office...)

Const SHCONTF_NONFOLDERS=&H40
Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
strPath="C:\Testing"

ScanDirectory(objFSO.GetFolder(strPath)

Set objFSO=Nothing
wscript.quit

Sub ScanDirectory(objFolder)
  ScanFiles objFolder
  For Each fld in objFolder.Subfolders
    ScanDirectory fld
  Next
End Sub

Sub ScanFiles(objFolder)
  For each file in objFolder.Files
    Compress(file)
  Next
End Sub

Sub Compress(fil)
  strPath=Left(fil,InstrRev(fil,"\"))
  strFile=Mid(fil,InstrRev(fil,"\")+1)
  strExt=Mid(strFile,InstrRev(strFile,".")+1,3)
  If Lcase(strExt)="log" Then
    strZip=strPath & Replace(strFile,"log","zip")
    set zipFil=objFSO.CreateTextFile(strZip)
    zipFil.WriteLine chr(80) & Chr(75) & Chr(5) & Chr(6) & String(18,0)
    zipFil.Close
    Set oApp=CreateObject("Shell.Application")
    oApp.NameSpace(strZip).CopyHere strPath & strFile
    wscript.sleep 7000 'wait for file to be compressed
    Set oApp=Nothing
    Set zipFil=Nothing
    If objFSO.FileExists(strZip) Then objFSO.DeleteFile (fil) 'deletes file if the zip was created
  End If
End Sub
0
 

Author Comment

by:hpsuser
ID: 18847425
thanks, we've just launched the system that this will involve, when I get a chance I'll come back to this to implement.
0
 

Author Comment

by:hpsuser
ID: 19103212
SirBounty - I forgot about this one, finally got around to trying it and it worked, thanks for your help.
0

Featured Post

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question