I have a batch file I use to rename files with the date and time
stamp:
RENAME W:\TEST.TXT TEST_%date:~-4,4%%date:~-7,2%%date:~0,2%_%time:~0,2%
%time:~3,2%%time:~6,2%.TXT
This will work correctly if the time is after 10AM, if the time is
between 01:00 and 09:59 it will fail. Can anyone help me out and let
me know why?
For example if I run the BATCH file at 10:01 I will see
TEST_20091217_100112.TXT, if I run it at 09:58 the file command fails
with error "The syntax of the command is incorrect."
Thanks,
Brett
>I have a batch file I use to rename files with the date and time
>stamp:
>
>RENAME W:\TEST.TXT TEST_%date:~-4,4%%date:~-7,2%%date:~0,2%_%time:~0,2%
>%time:~3,2%%time:~6,2%.TXT
>
>This will work correctly if the time is after 10AM, if the time is
>between 01:00 and 09:59 it will fail. Can anyone help me out and let
>me know why?
The time will have a leading space character beween 1 and 10am and your
rename command doesn't support longfilename elements.
>For example if I run the BATCH file at 10:01 I will see
>TEST_20091217_100112.TXT, if I run it at 09:58 the file command fails
>with error "The syntax of the command is incorrect."
This should be more robust:
set d=%date:~-4,4%%date:~-7,2%%date:~0,2%
set d=%d: =_%
set t=%time:~0,2%%time:~3,2%%time:~6,2%
set t=%t: =0%
RENAME "W:\TEST.TXT" "TEST_%d%_%t%.TXT"
Thank you foxidrive, this is perfect.
Set your computer to show ISO 8601 date & time format, and all such
problems will be behind you.
Read <http://en.wikipedia.org/wiki/ISO_8601>.
--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm estrdate.htm js-dates.htm pas-time.htm critdate.htm etc.
Details to, "Set your computer to show ISO 8601 date & time format", would
be worthwhile to include since the standard alone does not explain it. OTOH,
many people do not have necessary permission required to modify date/time
format, so perhaps it is time you consider an alternate method that does not
require system settings modifications.
--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)
Evidently your memory and wits are ageing further.
I have, and offer, as you should recall, NOWMINUS, via sig line 3, for
those rightfully asking in this newsgroup, and for some of those asking
in a.m.b.nt (but maybe not for 64-bitters).
One can also, in at least Win98 & later, do it in Windows Scripting
Host, with either JavaScript or VBScript; my batch pages, via sig,
refer.
I suppose one can do it in PowerShell, too.
Nevertheless, what I wrote is strictly accurate (provided one does not
import batch files written strictly for those who use FFF date format.
--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk DOS 3.3 6.20 ; WinXP.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS EXE TXT ZIP via <URL:http://www.merlyn.demon.co.uk/programs/00index.htm>
My DOS <URL:http://www.merlyn.demon.co.uk/batfiles.htm> - also batprogs.htm.
We both know there are many methods to collect date/time elements, and we
both know you thrive to antagonize, but your time would have been better
spent had your post related to what I mentioned.
/\/\
/ / /
_/,/ /
_/` (/"/////,
( '```--.___
/' _), ,- '-.
/, / \ (\ \,
\_()/ \) )' =_ )) |
| | .// _/)
( ( \_ // /
\ >_,\ (/)= /
| | | \ #\| /
|=| |=|\ ( (
(=> ( >( >),)
| | |=| \ ( (
/ / / / ) |/
\ /_( /_( , || )/.,_
). /\\_(\,/,_//-_/ /_(_( /
,\. .- '-'-'-,)\/.'))