Solved

BAT file to change file name

Posted on 2011-09-23
7
265 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
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
LVL 9

Accepted Solution

by:
jsdray earned 500 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Suggested Solutions

Title # Comments Views Activity
ASP:Radiobuttonlist/asp:RadioButtonListItem custom styling 1 55
ASP.NET MVC 2 40
encoding an href string 2 24
reading excel file in .net 2 14
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

840 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