Solved

BAT file to change file name

Posted on 2011-09-23
7
262 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
  • 3
  • 3
7 Comments
 
LVL 9

Expert Comment

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

Author Comment

by:Camillia
Comment Utility
current time
0
 
LVL 11

Expert Comment

by:brutaldev
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 9

Accepted Solution

by:
jsdray earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
thank you. I will try
0
 
LVL 7

Author Comment

by:Camillia
Comment Utility
going to try this now, thanks
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video discusses moving either the default database or any database to a new volume.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now