Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 17544
  • Last Modified:

How to rename a file name to a prefix + current date in DOS batch file

Hi

My machine is an NT.  Everyday, there will be a file (i.e. abc.txt) output to my NT server & I need to write a program (in DOS batch file) to rename the file from abc.txt to abc210300.txt

The 210300 means 21st March 2000, if today is 21/3/2000.  So, everyday the program will be scheduled to run and reanme the abc.txt to

"abc" + current date + ".txt"

This is the batch file commands I have now, but I don't know how to put in the date portion.  

@echo off
echo.

rename c:\temp\abc.txt abc123.txt

@echo off


Thank you.
n_chai
0
n_chai
Asked:
n_chai
1 Solution
 
vikiingCommented:
You will need the help of a tiny program (I can write it for you) to accomplish that job.

Unfortunately, there is no way to do what you need directly from DOS commands; thus, it's impossible to write a .BAT program that make that.
0
 
viper5by5Commented:
there is no way to write a batch file(*.BAT, with out using some sort of program.

I could wirte the program for you, use some programs i have at home.
0
 
guyssCommented:
you can use the 4NT shell instead of cmd.exe

then you'll be able to do these things.
4NT is available from
http://www.jpsoft.com
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
Somebody_elseCommented:
you can wirte code in a text file and save it as file.bat and it will be a batch file.
0
 
plusignCommented:
You can try this site

http://www.calweb.com/~webspace/batch/sa
mples/namedate.txt
0
 
saraganiCommented:
I can build a little program for you in GWBASIC and it will work fine.
0
 
vikiingCommented:
Forget it, dude; it seems to be nobody there... :(
0
 
temadanCommented:
Hello
This works for the batch file (.bat) file in MS-DOS on Win2000.

for "abc" + current date + ".txt" you will have to add the code
%date:~4,2%-%date:~7,2%-%date:~10%
at the place you want your current date to appear.

e.g.
ren c:\temp\abc.txt abc%date:~4,2%-%date:~7,2%-%date:~10%.txt

Enjoy :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now