Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a folder that, besides other things, has folders named after dates, e.g. 20110908 20110909 and so forth. Every night, I would like to run a tool that checks for all folders matching that datemask (could be 201*), and bzip2 any of them that don't already have a similarly named bzip2 archive. And ideally, if after bzip2-ing the folder contents change, I would like to re-bzip2 them.

Is there a tool out there that would help me?

share|improve this question

2 Answers 2

The command line version of 7-Zip can help you here. You can create a batch file that you schedule using Task Scheduler. You would want to use 7-Zip's update switch "u". A script something like the following might do the trick:

for /f %%F IN ('dir /b 201*') (

    REM Extract
    7z e %F.tar.bz2 %F.tar

    REM Update archive
    7z u %F.tar -uq2r2y2z2w2 %F

    REM Compress
    7z a %F.tar.bz2 %F.tar

    REM Delete tar
    del %F.tar

)

If you can get away with using zip or 7z format, then you can skip the "extract, then recompress" steps and simply run the update step.

share|improve this answer
    
Perfect, thanks! –  Cookie Sep 11 '11 at 20:55
up vote 0 down vote accepted

I resorted to using python with a bzip2.exe for Windows.

#!/usr/bin/env python
import os
import subprocess

rootdir = "C:/XXX/"
for root, subFolders, files in os.walk(rootdir):
    for file in files:
    filename = os.path.join(root,file)
    if(os.path.splitext(filename)[1] != ".bz2"):
        print("Compressing "+filename+"...")
        process=subprocess.Popen('bzip2.exe %s'%(filename),shell=True)
        process.wait()
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.