How to Automatically create folders named by Date

Had an interesting scenario with an old Line of Business application for a client yesterday.

It was an old system that relied on Floppy Disks for Backups. The client was aware (due to my constant nagging!) that Floppy Disks weren’t to be trusted as a backup medium, and so had purchased a couple of USB Key-Disks to store the backups onto instead.

Fooling the system into thinking a USB disk was a Floppy was fairly simple, but where the system fell over was in the fact it didn’t overwrite the last backup… it simply threw a hissy-fit and crashed out!

Obviously, the client could manually delete the previous backup – but I looked for an automated solution.

The result? A small batch file that creates a folder within a sub-folder with that days date, with the batch-file set to “autorun” each and every time the USB Key Disk is inserted for the clients convenience.

Batch File:-

set dd=%date:~0,2%
set mm=%date:~3,2%
set yyyy=%date:~6,4%
mkdir “PayrollBackup%yyyy%-%mm%-%dd%”
move pay-data* “Backup%yyyy%-%mm%-%dd%”

Autorun File:-

[autorun]
open=Update.bat
action=Ready USB Disk for Backup
label=Backup

I don’t get many chances to write scripts nowadays, even very basic ones, so this was a good chance for me to get geeky. šŸ™‚

Reader Interactions

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Send this to a friend