Solved

How can I create a Windows 2000 task that will check if a file exists and then rename it if it does

Posted on 2010-08-29
14
263 Views
Last Modified: 2012-05-10
I have no experience in scripting whatsoever.  How do I create a task that will run in the Windows 2000 task scheduler that will:

1.  Check is a file (for example. backup.bkf) exists, and if so;
2.  Rename it to the same file name with today's date appended (for example, backup20100828.bkf)?

I know this is trivial but I have not idea how do do it and even what the name of the job file should be.

Thank you.
0
Comment
Question by:Randy_R
  • 8
  • 6
14 Comments
 
LVL 2

Expert Comment

by:hilltop
ID: 33554406
Create a new text file and name this file with an extension .bat

Paste the following code into this new file then replace replaceme.txt with your filename or path+name, save your changes and schedule away.

IF NOT EXIST replaceme.txt GOTO SavedIt
RENAME replaceme.txt renamed.txt
:SavedIt
0
 
LVL 2

Expert Comment

by:hilltop
ID: 33554433
Sorry use this instead.

For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a-%%b-%%c)
IF NOT EXIST tt.txt GOTO SavedIt
RENAME tt.txt %DATE%.txt
:SavedIt
0
 

Author Comment

by:Randy_R
ID: 33554439
Thanks. Do I insert the path with respect to both files in the rename or just the first one, if I want the file to be renamed in the same folder?

Also, how do I generate renamed.txt to be the same name as replaceme.txt but with todays date automatically generated and appended to the name (i.e. backup.bkf get renamed to bacup<todays date>.bkf?  I don't want to provide the date but have it generated automatically.
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

Author Comment

by:Randy_R
ID: 33554460
Just saw the 2nd post.  Can you please give me the fullcode for turning backup.bfk into backup20100828.bkf assuming today is 8/28/2010?
0
 
LVL 2

Expert Comment

by:hilltop
ID: 33554461
Use the second pasted code. I left tt.txt there instead of replaceme.txt you may notice. You can use paths or just run the bat file in the same directory as the files.
0
 
LVL 2

Expert Comment

by:hilltop
ID: 33554463
Reply:
Just saw the 2nd post.  Can you please give me the fullcode for turning backup.bfk into backup20100828.bkf assuming today is 8/28/2010?

Sure I will: hold on just a sec
0
 

Author Comment

by:Randy_R
ID: 33554465
Does the path/filename need quotes aorund it if there are spaces in it?
0
 
LVL 2

Accepted Solution

by:
hilltop earned 500 total points
ID: 33554475
@echo off
IF NOT EXIST c:\yourpathto\backup.bfk GOTO SavedIt
For /f "tokens=2-4 delims=/ " %%a in ('date /t') do (set date=%%a%%b%%c)
RENAME c:\yourpathto\backup.bfk %DATE%.bkf
:SavedIt

I added the path inof which you can use or remove.
0
 

Author Comment

by:Randy_R
ID: 33554484
Great!   How do I tell the task scheduler to "run": this .bat file weekly?
0
 
LVL 2

Expert Comment

by:hilltop
ID: 33554486
0
 

Author Comment

by:Randy_R
ID: 33554493
Thanks so much.  I will try this later and repost tomorrow, if I have a problem.

Thanks again!
0
 

Author Comment

by:Randy_R
ID: 33554528
Ok, this renamed the file to the date.bkf, not originalfilename+date.txt.

Also date format is mmddyear.  Is there a way to make it yearmmdd?
0
 

Author Comment

by:Randy_R
ID: 33554558
Nevermind.  I got it.  Thanks so much!!
0
 

Author Closing Comment

by:Randy_R
ID: 33554560
Great, timely advice!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

832 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