DateTime-stamp on files/directories

You’ve always have some junk or temporary files laying around. Everybody sooner or later have to figure out they’re own way to archive them or just store them temporarily in some other place that your project main dir, your hard drive main dir, or desktop.

I’ve seen a few practises that does not work for me, like temp dirs name: o, oo, ooo, or !, !!, !! 😉

I’ve been using a temp directories marked with a timestamp, and it’s very easy to notice when it is old and can be deleted without any harm. Simple.

A long time ago I’ve spend not so little time to forge a solution, the best of both worlds, merging cygwin’s date and a neat windows shell command I came across:

cmd /c FOR /F "TOKENS=1* DELIMS= " %A IN ('D:usrcygwinbindate.exe +%Y%m%d-%H%M') DO mkdir %A

I still does not understand it, windows shell programming was always something not-logical and hard to learn just „because it must done our way”, meaning other than on -nix systems.

Lately I had to do similar thing, but without cygwin, maybe after few years have passed Google could find a nicer solution, or I just missed it previously:

cmd /c md "%date:-=%-%time:~0,2%%time:~3,2%"

Clean and understandable (if you want to squeeze your brain a little bit 😉 ), and can be used for variety of things, eg. naming backup files 😉

Leave a Reply

Back to Top