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 need to compress a specific folder in Windows on an hourly basis and move it to a different destination folder. How can I do this?

share|improve this question

migrated from stackoverflow.com Dec 11 '09 at 7:35

This question came from our site for professional and enthusiast programmers.

    
try cobian backup, it can do that for you without hassle –  Alix Axel Dec 12 '09 at 17:18

4 Answers 4

I have a batch script that does something similar for packaging up release builds of the game I'm working on. I've adapted it, and you can probably use something similar to the following:

@echo off
cd folder
zip -9 -r Filename.zip *
echo Done.

The zip switches:

  • -9 attempts the best compression
  • -r causes directory recursion

If you need to copy resources, or a folder tree for example (as I needed to do), you can use xcopy to effect this.

echo Copying resources to Release dir...
xcopy resources bin\Release\Resources /Y /E /I

The various command line switches here:

  • cause automatic overwriting of existing files (/Y)
  • copy all folders, including empty ones (/E)
  • basically enables copying directory trees (/I)

Hopefully this should give you enough information to let you set up the batch script for yourself. Then, as others have said, you can use Scheduled tasks to cause the script to be run hourly. If you don't have the zip command line exe, I use this one. Copy it to C:\Windows\System32 and it should be accessible from all batch scripts.

Update

To suit your additional comment about naming the zip with the current timestamp, I propose the following solution - Add the following lines to the end of the batch script you have set to run hourly.

set timestamp=%date:~10,4%%date:~7,2%%date:~4,2%%time:~0,2%%time:~3,2%%time:~6,2%
ren OldZipFileName.zip %timestamp%.zip

This will rename the old zip file to the new one, with the format YYYYMMDDHHmmSS; that is, year-month-day-hour-minute-second. If you wish to add a prefix or suffix to the filename, do that before or after the %timestamp% section, for example:

ren OldZipFileName.zip build_%timestamp%_debug.zip

Update again

The reason for the large and unwieldy set timestamp=... line is because the standard formats of %date% and %time% aren't the best for what we want to do. If we echo them to the console to see what they look like normally, we'll get something similar to this:

> echo %date%
Sun 13/12/2009
> echo %time%
 2:53:31.60

So, we use the fancy substring function of batch variables, like so: %variablename:~startindex,length%. As you can see above, you'll need to repeat it once for each segment that you wish to copy. So, in my case, to get the output filename in the format of YYYYMMDDHHMMSS, I needed to copy three parts from each of the %date% and %time% variables, using the substring. Join all those parts up, and you get that long line I wrote up there earlier. To give an example of these parts individually:

> echo %date%
Sun 13/12/2009
> echo %date:~10,4%
2009
> echo %date:~7,2%
12

Hope this helps clarify things for you!

share|improve this answer
    
Hrm ,I'm interested in that game. What language are you using, what sort of game? –  Moshe Dec 11 '09 at 7:44
    
I'm writing it in C++, and it's going to be using the basic premise of tetris but taking a twist in a "new, uncharted direction". Or at least it should, assuming I get around to finishing it. So basically, C++ & arcade game with a tetris theme. –  Sticky Dec 11 '09 at 7:48
    
I have updated my answer to reflect changing the filename to include a timestamp, as per your comment. –  Sticky Dec 11 '09 at 9:41

I am far from Windows, but here is a generic idea: Just keep a track of elapsed time in your program and every 3600s, use the compression specific library calls and primitives to do what you want to achieve.

share|improve this answer

Write a batch file that does the compression and copying. Then setup Scheduled Tasks to run it every hour.

share|improve this answer

You probably want to use the Task Scheduler. In Vista and 7 you get to it by typing in taskschd.msc from the Run dialog.

share|improve this answer

Your Answer

 
discard

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