You are not logged in.
Pages: 1
I am new to Microsoft OS commands but have not yet been able to successully rename a file with today's date. I have tried using the StampMe.cmd (code below) but i receive an error when it reaches the command line
FOR /f "tokens=6-8 delims=/ " %%G IN ('NET TIME \\%computername%') DO (SET _mm=%%G SET _dd=%%H SET _yy=%%I)
ERROR: %%G was unexpected at this time
Any help on this error or other methods which i could rename a file would be much appreciated
Thanks,
Dan
Offline
Apologies i forgot to attach the script
@ECHO off
SETLOCAL
IF [%1] NEQ [] goto s_start
:: Author - Simon Sheppard, July 2003
:: Tested for Windows NT, 2K, XP
ECHO STAMPME.cmd
ECHO REName a file with the DATE/Time
ECHO.
ECHO SYNTAX
ECHO STAMPME TestFile.txt
ECHO.
ECHO STAMPME "Test File.txt"
ECHO.
ECHO STAMPME "c:\docs\Test File.txt"
ECHO.
ECHO Will rename the file in the format "Test File-02-12-27@16-55.txt"
ECHO.
ECHO In a batch file use CALL STAMPME ...
:: To change the filename format just change around the last line below
GOTO :eof
:s_start
SET _file=%~n1%
SET _pathname=%~f1%
SET _ext=%~x1%
::Get the date
:: note ISO 8601 date format would require 4 digit YYYY Year)
FOR /f "tokens=6-8 delims=/ " %%G IN ('NET TIME \\%computername%') DO (
SET _mm=%%G
SET _dd=%%H
SET _yy=%%I
)
:: Get the time
FOR /f "tokens=1,2 delims=: " %%G IN ('time/t') DO (
SET _hr=%%G
SET _min=%%H
)
ECHO Today is Year: [%_yy%] Month: [%_mm%] Day: [%_dd%]
ECHO The time is: [%_hr%]:[%_min%]
REN "%_pathname%" "%_file%-%_yy%-%_mm%-%_dd%@%_hr%-%_min%%_ext%"
Offline
Which OS are you running?
if you run just
NET TIME \\%computername%
what does that return?
Offline
Hi,
Just read this post and ran the command...this is the output (I have sanitised it for security):
U:\>net time
Current time at \\servername.domain.com is 10/24/2006 5:18 PM
The command completed successfully.
U:\>
This is a networked drive, and the servername returned is not my DNS/DHCP/File or AD server. Not sure why it picked it.
Anyway, running it again as follows, I can choose which computer on the network to query for the time:
U:\>net time \\myHostname
Current time at \\myHostname is 10/24/2006 5:23 PM
The command completed successfully.
U:\>
Cheers.
Offline
Current time at \\myHostname is 10/24/2006 5:23 PM
The command completed successfully.
Hmm, that should work correctly
the tokens are
Current time at \\myHostname is 10/24/2006 5:23 PM
^1 ^2 ^3 ^4 ^5 ^6 ^7 ^8
So tokens 6-8 should have the right things
What do get from just
echo %computername%
Offline
Pages: 1