Solved

rename a file as yymmddhhss.txt

Posted on 1998-12-01
9
300 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
  • 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Recently Microsoft released a brand new function called CONCAT. It's supposed to replace its predecessor CONCATENATE. But how does it work? And what's new? In this article, we take a closer look at all of this - we even included an exercise file for…
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now