PC Review


Reply
Thread Tools Rate Thread

CMD date prepend problem

 
 
bobby.gillette@gmail.com
Guest
Posts: n/a
 
      9th Nov 2006
Found this snippet of code from Matthias on another thread and am
trying to get it to prepend the date to an existing filename (that's
created via another CMD script).

Here's what I have (it renames but doesn't add any date information to
the filename):

======Code begins==========
::AppDate.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@echo off & setlocal EnableExtensions DisableDelayedExpansion
Call :GetDate yy mm dd
set mydate=%yy%%mm%%dd%
for %%A in (Charleston_Last_logon.txt) do (
ren "%%~fA" "%mydate%%%~nxA"
ren "%%~fA" "%%~nA%mydate%%%~xA"
)
goto :EOF
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:GetDate yy mm dd
::
:: By: Ritchie Lawrence, 2002-06-15. Version 1.0
::
:: Func: Loads local system date components into args 1 to 3.
:: For NT4/2000/XP/2003.
::
:: Args: %1 var to receive year, 4 digits (by ref)
:: %2 var to receive month, 2 digits, 01 to 12 (by ref)
:: %3 Var to receive day of month, 2 digits, 01 to 31 (by ref)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

setlocal ENABLEEXTENSIONS
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
set %%a=%%d&set %%b=%%e&set %%c=%%f))
endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
::EOF::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


==========End of code===========

What I'm trying to do is rename the file called
Charleston_Last_Logon.txt with the date prepended to it (so I can run
the file once a month and retain the previous month's results).

Any help would be greatly appreciated

Bobby

 
Reply With Quote
 
 
 
 
billious
Guest
Posts: n/a
 
      9th Nov 2006

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Found this snippet of code from Matthias on another thread and am
> trying to get it to prepend the date to an existing filename (that's
> created via another CMD script).
>
> Here's what I have (it renames but doesn't add any date information to
> the filename):
>
> ======Code begins==========
> ::AppDate.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>
> @echo off & setlocal EnableExtensions DisableDelayedExpansion
> Call :GetDate yy mm dd
> set mydate=%yy%%mm%%dd%
> for %%A in (Charleston_Last_logon.txt) do (
> ren "%%~fA" "%mydate%%%~nxA"
> ren "%%~fA" "%%~nA%mydate%%%~xA"
> )
> goto :EOF
> :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>
> :GetDate yy mm dd
> ::
> :: By: Ritchie Lawrence, 2002-06-15. Version 1.0
> ::
> :: Func: Loads local system date components into args 1 to 3.
> :: For NT4/2000/XP/2003.
> ::
> :: Args: %1 var to receive year, 4 digits (by ref)
> :: %2 var to receive month, 2 digits, 01 to 12 (by ref)
> :: %3 Var to receive day of month, 2 digits, 01 to 31 (by ref)
> :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>
> setlocal ENABLEEXTENSIONS
> set t=2&if "%date%z" LSS "A" set t=1
> for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
> for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
> set %%a=%%d&set %%b=%%e&set %%c=%%f))
> endlocal&set %1=%yy%&set %2=%mm%&set %3=%dd%&goto :EOF
> ::EOF::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>
>
> ==========End of code===========
>
> What I'm trying to do is rename the file called
> Charleston_Last_Logon.txt with the date prepended to it (so I can run
> the file once a month and retain the previous month's results).
>
> Any help would be greatly appreciated
>
> Bobby
>


Works fine for me (XP/H)

* You have 2 "rename" lines -
ren "%%~fA" "%mydate%%%~nxA"
ren "%%~fA" "%%~nA%mydate%%%~xA"

Obviously only the first will be executed.

renamed "Charleston_Last_logon.txt" to "20061110Charleston_Last_logon.txt"
dutifully for me.

What do you mean by
"(it renames but doesn't add any date information to the filename)" ?

if the file is renamed, what is it renamed TO for you?


 
Reply With Quote
 
Matthias Tacke
Guest
Posts: n/a
 
      10th Nov 2006
(E-Mail Removed) schrieb:
> Found this snippet of code from Matthias on another thread and am
> trying to get it to prepend the date to an existing filename (that's
> created via another CMD script).
>
> Here's what I have (it renames but doesn't add any date information to
> the filename):

....
>
> What I'm trying to do is rename the file called
> Charleston_Last_Logon.txt with the date prepended to it (so I can run
> the file once a month and retain the previous month's results).
>
> Any help would be greatly appreciated
>
> Bobby
>

Hi Bobby,
instead of reposting you should have included a link to the original
posting:

http://groups.google.com/group/micro...cd9c8bf8c43d93

Later on in that thread it is mentioned to choose one of the ren
commands. Either prepending or appending the date.

::AppDate.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off & setlocal EnableExtensions DisableDelayedExpansion
Call :GetDate yy mm dd
set mydate=%yy%%mm%%dd%
for %%A in (Charleston_Last_logon.txt) do ren "%%~fA" "%mydate%%%~nxA"
goto :EOF
---snip---


Provided you have an english windows that should work.

HTH
Matthias
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I prepend text (%3-7) to specific indented paras usg replac. =?Utf-8?B?YnJhaWxsZXBybw==?= Microsoft Word Document Management 1 24th Oct 2007 11:15 AM
::: Date Comparison Problem or Date Formula or Date Macro ::: infojacques@gmail.com Microsoft Excel Discussion 3 13th Jul 2007 10:08 AM
How to AUTOMATICALLY prepend/pass a "/U" switch to cmd.exe when executing a *.bat batch file ? Thommy Kanther Windows XP Help 3 19th Mar 2007 02:57 AM
How to AUTOMATICALLY prepend/pass a "/U" switch to cmd.exe when executing a *.bat batch file ? Thommy Kanther Windows XP General 0 18th Mar 2007 09:18 AM
How to prepend ctr in a macro? Chuck Roberts Microsoft Excel Misc 2 18th Jun 2004 05:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:43 PM.