How can I rename a text file with the YYYYMMDDNNSSZZ?

I would like to rename a file at this path, C:\Data\original.file.txt with a time stamp following the YYYYMMDDNNSSZZ.original.file.txt
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

What does NN SS ZZ stand for? Aside from Year Month Day I'm guessing you want hour, minute, second...but I don't get the NN SS ZZ annotation.
100questionsAuthor Commented:
I believe the NNSS stands for Nano Seconds.  Not sure about the ZZ.   We can leave it at nanoseconds.
Can you modify my code below? This does YYYYMMDDHHMMSS

@echo on
for /F "tokens=1-3 delims=:." %%a in ("%time%") do (
   set timeHour=%%a
   set timeMinute=%%b
   set timeSeconds=%%c
set year=%date:~10,4%
set month=%date:~4,2%
set day=%date:~7,2%
ren c:\data\myfile.txt %year%%month%%day%%timeHour%%timeMinute%%timeSeconds%.myfile.txt
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

NN isn't anything.
zz would be time offset from UTC.
Case does matter!  Here's a link with all the specifiers.
I'm assuming you want something like this (in PowerShell).
But if not, reference the above link to get exactly what you want.  Next, I'm not clear on whether you want the time to come from the current time, or maybe the timestamp on a file like its last modified time or creation time.
100questionsAuthor Commented:
The time would have to come from the current time.
Steve KnightIT ConsultancyCommented:
If you want batch to rename then see this article of mine on the subject: 

e.g. yyyy-mm-dd-hh-mm.cmd there.  Can soon add seconds etc.

But you need to clarify what you actually want, i.e. an example filename.

Bill PrewIT / Software Engineering ConsultantCommented:
Easy enough to rename a file with current time info, but you need to specify what the NNSSZZ really is.  I saw you mentioned "nanoseconds" but that isn't clear enough to know what you mean.

Here's a one line PS script to rename a file.  Remove the -confirm switch if you don't want that option.
Get-Item somefile.txt | % { $newname = "$((Get-Date).ToString("yyyyMMddHHmmsszz")).$($_.Name)";  Rename-Item $_ $newname -Confirm }

Open in new window

100questionsAuthor Commented:
Thanks footech, how can I specify the path?
I also want the file to be renamed to a dateinfo_new.txt
Is this possible?
Just specify the full path to the file in the first part.
Get-Item c:\temp\somefile.txt

I'm not clear on what you're asking.  Maybe the following?
Get-Item c:\temp\somefile.txt | % { $newname = "$((Get-Date).ToString("yyyyMMddHHmmsszz"))_new$($_.extension)";  Rename-Item $_ $newname -Confirm }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
100questionsAuthor Commented:
Thanks footech.  What if I want to change the file name after it's been dated, as newfile.txt?
I don't understand what you're asking.  I've already shown what's needed for a couple renames.  If you want to name it something else, just make the substitution in the code.
100questionsAuthor Commented:
I believe this should work.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.