G
guard
I'm trying to create a batch file that will rename another
file and include a timestamp in the file name. For
example, incoming file is named MyTestFile.dat and I want
to rename it to MyTestFile-180623.dat
Any advice would be appreciated I'm sure it's quite a
simple line or two of code. Thanks.
Under Windows NT/2K/XP/K3, this can be done in two self-documenting lines of
code using the Mount/\Command "GetLogTime".
For example:
%.GetLogTime%
REN MyTestFile.dat MyTestFile-%#LogTime%.dat
GetLogTime returns hhmnss CONSISTENTLY under NT/2K/XP/K3 and saves this
value in variable %#LogTime%. Output is always the same regardless of
variations in operating systems and regional date/time formats.
See (http://TheSystemGuard.com/MtCmds/GetValue/GetLogTime.htm#GuardNotes)
for more information and a color-keyed example.
*******
GetLogTime is part of the .GetValue Series of Mount/\Commands.
Some other Get[Value] commands are:
GetLogDate (yyyymmdd)
GetIPAddr (nnn.nnn.nnn.nnn)
GetMac (xx-xx-xx-xx-xx-xx)
GetFree (free space on current drive in bytes)
GetRole (Server/Wkstn)
Each one displays to the console AND saves the value to a variable for
further processing. See them all at
(http://TheSystemGuard.com/MtCmds/GetValue)
*******
The complete .Mount/\Command Set contains over 200 commands. These
are extensions to the builtin command set that perform CONSISTENTLY across
NT/2K/XP/K3 and provide self-documenting code for your scripts.
See (http://MountCommands.com) for more information.
*******
Notes:
1. .Mount/\Commands are constructed using ONLY builtin
commands common to all four platforms (NT/2K/XP/K3).
There is NO BINARY CODE, only scripting commands!
2. .M/\C's are NOT case sensitive. Mixed case is used
for Visual Clarity only.
3. The (FREE) Advanced NT/2K/XP Command Library (ntlib.cmd)
provides over 50 sample Mount/\Commands to assist with
writing and documenting cross-platform scripts.
You can obtain it at (http://ntlib.com).
*******
All the commands internal to cmd.exe are documented in "Mounted Help" pages
in TheGuardBook (http://TheSystemGuard.com/TheGuardBook/CCS-Int).
This includes a color-keyed page highlighting the differences between all
internal commands in NT/2K/XP/K3.
The "Common Help" from each OS's help screen is also available for
comparison.
*******
-tsg
____________________________________________________________
TheSystemGuard.com | BoomingOrFuming.com | MountCommands.com
Free and "Almost Free" Knowledge for Windows System Admins!