Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming a file in DOS........... 1

Status
Not open for further replies.

scottyjohn

Technical User
Nov 5, 2001
523
GB
Hi all,
I have an application which dumps a text file to a location on a server. Unfortunately it cant rename the file using a dynamic label such as including the date, so it overwrites the file everytime it exports the file. Is there a way in DOS of renaming a text file using sonme sort of dynamic labelling such as including the date? John
 
Did you try REN XXX.TXT YYY.TXT (XXX & YYY being the file name)? WMH
MCP+I, MCSE
smashfreakb.gif
 
Yes that does work but I want to run that command line with a scheduling package so that it names it something different everytime like 001.txt John
 
Sorry, but trying to incorporate that kind of data into a filename is beyond DOS. DOS doesn't even provide for naming files in a pattern (1.txt 2.txt, etc).

You can do what you would like, but you need to use a utility to do so. If you get creative, you can certainly accomplish that without any problems. In fact, a quick search on shows me a dos util called Now 1v02 (file name now-1v02.zip) that should do what you want. Free download (don't know the ware type), check it out.

Looks like it will take the just about any date/time info you could want and translates it into DOS friendly format specifically for use in naming unique filenames in a batch file. Bingo!

Good luck! Mudskipper
 
Right mudskipper

DOS is pretty limited.

You could get Kixtart which might do that, expect ir would, or write a very small BAS program.

The following winds up to be a 4,128 byte long EXE (done in BCX/LCC) but could be done in VB.


Code:
dim a$, i
  ! strdate (a);  for(i=0;i<strlen(a);i++) if (a[i]=='/') a[i]='.';
  a$ = &quot;command /c ren &quot; & argv$[1] & &quot; &quot; _
      & chr$(34) & argv$[1] & a$ & chr$(34)
 ? a$
 shell a$
end

It renames X to X09.20.02 and one could tag on the timestamp pretty easily.


 
I have the following saved as a batch file and use task scheduler to run it at a certain time each morning. It moves the file and then renames it with the current date in a dd-mm-yyyy format (so if your american you might want to swap the %%a and the %%b over in the date=%%a-%%b-%%c line)


**********************************************************
move c:\TQMDATE.ZIP c:\TQMCOPY\TQMCOPY.zip

FOR /f &quot;tokens=2-4 delims=/ &quot; %%a in ('DATE/T') do SET date=%%a-%%b-%%c

rename TQMCOPY.zip %date%.zip
delete TQMCOPY.zip
**********************************************************

Alex
 
Sorry, thought that this was in the windows 2k forum, it doesn't work in 9x for some reason. All the best trying to resolve it.

Alex
 
Hi ScottyJohn,

I knew there was a simple solution lurking somewhere. It finally unlurked this AM

A really simple solution for Time/date in 9x/me command procedures (bat files).

If you run the command line:

timedate | call settimedate

then Date= and Time= will be set and you can then do something like

copy logfile &quot;%date%logfile&quot;

Tested and works on 98se2

Took a program but only... a few lines. The source as wellas the exe for TimeDate (4K) are on
It operates off the fact that if you set an environment paramter in a called batch file the parameter 'sticks' for the higher level.

The rest is Duh! simple, simply make a program to write a batch file
Set Time=...
Set Date=...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top