Dos Batch For a Starter

Cstelly

n00b
Joined
Jul 12, 2007
Messages
26
So Im trying to back up some files that I have in a directory and when I can get 1 batch file running I can get the others I just need to know the script I'd need to write.

Now I will admit I have close to no idea on wtf im doing so let me explain.

I have a set of files that I want to have their name changed each day.

The Current file is CS.TXT
I'd like for this file to have its named changed to Cs(CurrentDate).txt
So for today it would show Cs10012008.txt and tomorrow, Cs10022008.txt

I've been able to do a rename so wooh for me, so thats a start, I just cant get a date in between the file name and its extension. If anyone can give me some insight on what to do or point mein the right direction I'd greatly appreciate this.
 
Well it tried to create the file but %date% tries to put csWed 10/01/2008.txt

so its somewhat on the right path.
 
I tried that and am getting a Syntax error now. But this is what comes up when the batch is run

ren C:\test\cs.txt csWed 10012008.txt
syntax of the command is incorrect
 
Hmm... I'm not really the right person for this... I was honestly trying to guess based on the little experience I have from making 2 batch files. One of the things I just read online was that sometimes you have to swap ren with rename, so try:
Code:
Set FileDate=%date:/=%
rename x:\test\CS.txt CS%FileDate%.txt

I'm not sure how to get rid of the Wednesday part of the date parameter though...
 
Yeah the Wed part really isnt a problem... atleast I have the date in a format that can be put on as a file name. let me try that rename

and I really cant thank you enough for your insight.
 
Are you going to be archiving these in a folder? The only reason I ask is that you might be better off using YYYYMMDD so you can sort by ascending or descending within the folder. Although, I don't know how we'd format the date string like that...
 
Ok, I found some more info on the topic...

For YYYYMMDD use:
Code:
@echo off
echo. | date | FIND "(mm" > NUL
  If errorlevel 1,(call :Parsedate DD MM) Else,(call :Parsedate MM DD)
  goto :EOF
 :Parsedate ----------------------------------------------------------
  For /F "tokens=1-4 delims=/.- " %%A in ('date /T') do if %%D!==! (
     set %1=%%A&set %2=%%B&set YYYY=%%C
   ) else (
     set DOW=%%A&set %1=%%B&set %2=%%C&set YYYY=%%D)

(Set DateStamp=%YYYY%%MM%%DD%)

rename x:\test\CS.txt CS %DateStamp%.txt

For MMDDYYYY use:
Code:
@echo off
echo. | date | FIND "(mm" > NUL
  If errorlevel 1,(call :Parsedate DD MM) Else,(call :Parsedate MM DD)
  goto :EOF
 :Parsedate ----------------------------------------------------------
  For /F "tokens=1-4 delims=/.- " %%A in ('date /T') do if %%D!==! (
     set %1=%%A&set %2=%%B&set YYYY=%%C
   ) else (
     set DOW=%%A&set %1=%%B&set %2=%%C&set YYYY=%%D)

(Set DateStamp=%MM%%DD%%YYYY%)

rename x:\test\CS.txt CS %DateStamp%.txt
 
Back
Top