Solved

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

Posted on 2000-03-20
8
17,265 Views
Last Modified: 2010-04-30
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
Comment
Question by:n_chai
8 Comments
 
LVL 3

Expert Comment

by:vikiing
ID: 2644810
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
 

Accepted Solution

by:
viper5by5 earned 30 total points
ID: 2659925
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
 
LVL 1

Expert Comment

by:guyss
ID: 2659936
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
 
LVL 3

Expert Comment

by:Somebody_else
ID: 2687245
you can wirte code in a text file and save it as file.bat and it will be a batch file.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Expert Comment

by:plusign
ID: 2776183
You can try this site

http://www.calweb.com/~webspace/batch/sa
mples/namedate.txt
0
 
LVL 11

Expert Comment

by:saragani
ID: 2924605
I can build a little program for you in GWBASIC and it will work fine.
0
 
LVL 3

Expert Comment

by:vikiing
ID: 2924911
Forget it, dude; it seems to be nobody there... :(
0
 

Expert Comment

by:temadan
ID: 12471024
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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

If you are interested in the gaming world and want to try World of Warcraft, I'd recommend this basic set of add-ons to get you started.  All add-ons are available either by Google search or on Curse.com. For the person who doesn't want to get in…
Article by: ErwindeVries
Released on the 7th of September this real time strategy game sets a new bar for any real time strategy game. R.U.S.E. is a game made by Eugen Systems and published by Ubisoft and released for the PC, Playstation 3 and the Xbox 360. The setting o…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 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