How to move a file and append todays date to it using visual basic

1050 pts.
Tags:
File management
Visual Basic
Visual Basic Functions
Windows XP Pro
I have a report that produces an .rtf file with the same name daily. I want to move that file to a shared network location and append the date to the file so the old files remain when they are moved, plus the date will make it easier to search. How do i do that using .vbs? Here is an example of what I would like to do, of course this does not work: Dim fso, todaysDate Set fso = CreateObject("Scripting.FileSystemObject") todaysDate = Date() fso.MoveFile "C:report.rtf", "\networksharereport" & Date() & ".rtf"

Software/Hardware used:
win xp pro

Answer Wiki

Thanks. We'll let you know when a new response is added.

I found my own answer after some trial and error.
Hope it helps somebody else out
This is a batch file that takes that text file, or any file really, renames it then moves it to the shared location, then deletes the original file

echo on

ren c:\folder\new.txt new%date:~4,2%%date:~7,2%%date:~10,4%.txt

copy “C:\folder\new%date:~4,2%%date:~7,2%%date:~10,4%.txt” “\\servershare\folder1\folder2″

echo y | del “c:\folder\*”

———-

Your original script would have worked with some small modifications:

<pre>Dim objFSO, todaysDate, newname
todaysDate= date()
newname = “\\networkshare\report” & right(day(todaysDate)+100,2) & right(month(todaysDate)+100,2) & year(todaysDate) & “.rtf”
set objFSO = CreateObject(“Scripting.FileSystemObject”)
objFSO.MoveFile “C:\report.rtf” , newname</pre>

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following