?
Solved

BAT file to change file name

Posted on 2011-09-23
7
Medium Priority
?
270 Views
Last Modified: 2012-05-12
This is probably not the right forum but I'm not sure where to put this...

I'm looking for a BAT file to look at a drive folder and change the file name by adding a timestamp at the end of the filename...

For example, I have c:\folder1\myfile.csv.
I want to change it to c:\folder1\myfile20110923.csv

Never done a BAT file!
0
Comment
Question by:Camillia
[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
  • 3
7 Comments
 
LVL 9

Expert Comment

by:jsdray
ID: 36588334
What time are you wanting?  A hard coded time? The current time? or the File attribute time?
0
 
LVL 7

Author Comment

by:Camillia
ID: 36588425
current time
0
 
LVL 11

Expert Comment

by:brutaldev
ID: 36588436
http://www.intelliadmin.com/index.php/2007/02/create-a-date-and-time-stamp-in-your-batch-files/

For a simple one liner use this:
 
REN c:\folder1\myfile.csv c:\folder1\myfile%date:~-4,4%%date:~-7,2%%date:~-10,2%.csv

Open in new window

You can use patterns in the REN command (rename) as well. Put that line in a .bat file and you're good to go.
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!

 
LVL 9

Accepted Solution

by:
jsdray earned 2000 total points
ID: 36589063
echo off
cls

set MyDir=c:\temp\test

for /r %MyDir% %%i in (*.*) do (
call :doitnow %%i %%~ni %%~dpi %%~xi
)
goto eof

:doitnow
set MyFile=%1
set MyFileNameOnly=%2
set MyFilePath=%3
set MyFileExt=%4
RENAME %MyFile% %MyFileNameOnly%%date:~-4,4%%date:~-7,2%%date:~-10,2%%MyFileExt%
:eof
0
 
LVL 9

Expert Comment

by:jsdray
ID: 36589077
My last post will walk a tree for you...just change the MyDir Variable to the top level...  
0
 
LVL 7

Author Comment

by:Camillia
ID: 36589477
thank you. I will try
0
 
LVL 7

Author Comment

by:Camillia
ID: 36710491
going to try this now, thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

771 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