Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 327
  • Last Modified:

rename a file as yymmddhhss.txt

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
dickwanker
Asked:
dickwanker
  • 3
  • 2
  • 2
  • +2
1 Solution
 
b9Commented:
yyyymmddhhss.txt you mean ... and it can't be done with batch only.  Going to have to write some code.
0
 
cbo120897Commented:
I used fdate.exe for nearly the same functionality.
Take a look at: http://home.sprynet.com/sprynet/rlgreen/fileuti2.htm

bye cbo
0
 
carmineCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
carmineCommented:
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
 
dickwankerAuthor Commented:
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
 
b9Commented:
carmine.... that's not y2k compliant....
0
 
carmineCommented:
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
 
dickwankerAuthor Commented:
Carmine...

      You rule!

dickwanker
0
 
fireman44Commented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now