Compressing a folder periodically
Solution 1:
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!
Solution 2:
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.
Solution 3:
Write a batch file that does the compression and copying. Then setup Scheduled Tasks to run it every hour.
Solution 4:
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.