Showing posts with label timestamp. Show all posts
Showing posts with label timestamp. Show all posts

Friday, 1 August 2008

Batch programming summary

So been there, done that, time to move on from batch.
But before that, a quick list of all the batch programming scripts already available here:

Variables and spaces
Using CD /D
The Boring Black Hole
Working with arguments, part 1
Working with arguments, part 2
Working with arguments, part 3
Using CON... or not
How to clear the log file
Getting the batch file path
Retrieving argument file size
Comparing files by size
Reading from a file: part 1
Reading from a file, part 2: looping
Reading from a file, part 3: looping, part 2
Using FOR /D
Making and calling a subroutine, part 1
Making and calling a subroutine, part 2
Using The Substring Equivalent
Creating a timestamp
Using setlocal enabledelayedexpansion
The difference between :: and REM
Getting file information
Using help to help yourself (part 1)
Using help to help yourself (part 2): publishing batch help information in HTML format

Sunday, 20 July 2008

Batch programming tip#12: Creating a timestamp

Now we can substring, creating a timestamp is really easy.

This is one simple way of doing this using the %date% and %time% system variables to create timestamped files.


@echo off

:create_file
call :get_timestamp
type NUL > %timestamp%.file
goto eof

:get_timestamp
set d_stamp=%date:~11%%date:~8,2%%date:~5,2%
set t_stamp=%time:~0,2%%time:~3,2%%time:~6,2%%time:~9%
set timestamp=%d_stamp%%t_stamp%
goto blackhole

:eof
echo Press any key to quit...
pause > NUL
goto blackhole

:blackhole

(We reverse year, month and day so that the files are naturally sorted in the 'right' order.)

The create_file section retrieves the timestamp (e.g. 2008071719410698) created by the get_timestamp subroutine and uses it to create an empty file. Obviously this can have multiple uses like timestamping log information for instance.

(Note: day and month probably appear in a different order according to sytem locale.)

Thoughts?
Online Marketing
Add blog to our blog directory blog search directory Blog Directory Blogarama - The Blog Directory