Solved

rename a file as yymmddhhss.txt

Posted on 1998-12-01
9
306 Views
Last Modified: 2013-12-28
I need an NT batch job to read a file "input.txt" and rename it to yymmddhhss.txt based on the time it was created?
0
Comment
Question by:dickwanker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 

Expert Comment

by:b9
ID: 1795355
yyyymmddhhss.txt you mean ... and it can't be done with batch only.  Going to have to write some code.
0
 
LVL 3

Accepted Solution

by:
cbo120897 earned 50 total points
ID: 1795356
I used fdate.exe for nearly the same functionality.
Take a look at: http://home.sprynet.com/sprynet/rlgreen/fileuti2.htm

bye cbo
0
 
LVL 5

Expert Comment

by:carmine
ID: 1795357
b9 - "can't be done" I like a challenge

Create a batch file with the following contents

REM all on one line
for /f "skip=5 tokens=1-5 delims=/: " %%i in ('dir /tc "%1"') do ren "%1" %%k%%j%%i%%l%%m.txt
REM end of batch

call it with the filename you want to rename.  It does use UK date format you may have to nationalize that.  I could add path handling if you require it?
0
Schedule a Tour of the ATEN booth at InfoComm 2017

Tour the ATEN booth to see the the Latest Addition to the Modular Matrix Switch Series, New 4K HDMI Over IP Extender and more! Enter ATEN's Ultimate Giveaway Sweepstakes for a chance to win one of several great prizes, including an ATEN US7220 2-Port Thunderbolt 2 Sharing Switch!

 
LVL 5

Expert Comment

by:carmine
ID: 1795358
oops, missed a bit:

for /f "skip=5 tokens=1-5 delims=/: " %%i in ('dir /tc "%1"') do ren "%1" %%k%%j%%i%%l%%m.txt &goto end
:end

0
 

Author Comment

by:dickwanker
ID: 1795359
cbo's answer worked fine.  However, carmines answer using just a 4 line .cmd file was simpler and easier.  Thanks everyone for the help.
0
 

Expert Comment

by:b9
ID: 1795360
carmine.... that's not y2k compliant....
0
 
LVL 5

Expert Comment

by:carmine
ID: 1795361
b9
Ok, valid until 2080?

@ECHO OFF
FOR /F "skip=5 tokens=1-5 delims=/: " %%i IN ('dir /tc "%1"') DO (CALL :renit %1 %%k %%j %%i %%l %%m)&GOTO end
:renit
IF %2 LSS 80 (SET yr=2000) ELSE (SET yr=1900)
SET /A yr=yr+%2
REN "%1" %yr%%3%4%5%6.txt
GOTO end
:end
SET yr=

0
 

Author Comment

by:dickwanker
ID: 1795362
Carmine...

      You rule!

dickwanker
0
 

Expert Comment

by:fireman44
ID: 21910432
This worked great!  Thanks.  A bit of an explaination of the way "FOR" works would be nice, I had to play around with it for a while to get it to do what I wanted, but it helped loads.
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question