[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

BAT file to change file name

Posted on 2011-09-23
7
Medium Priority
?
272 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

650 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