Learn how to a build a cloud-first strategyRegister Now


work with a file name that changes based on that days date

Posted on 2009-12-17
Medium Priority
Last Modified: 2012-05-08
I need help with visual basic code for the following:

The file name is in this format:  rmr121709.lmc

I need to select the file in a directory that matches that days date, then rename the file to oldfile.txt, run a script on the file then rename the file back to rmr & todays date & .lmc.

Question by:Danean
LVL 18

Accepted Solution

philipjonathan earned 2000 total points
ID: 26077054
Dim fileName As String = "rmr" & DateTime.Today.ToString("MMddyy") & ".lmc"
File.Move(fileName, "oldfile.txt")

' ... run script here

File.Move("oldfile.txt", fileName)
LVL 27

Expert Comment

ID: 26077458
All you need to do is search directory for the day you want, pick that file.
Then run the script first then you can do two things.
1. You can then re name it
2. You can move it to another directory for  later archiving or
     just in case you have to find it again to re-run it.

I personnally when keep the name the same and move it to a directory for archiving.
LVL 65

Expert Comment

ID: 26077543
Hi, this VBS code will rename the file that you are referring to for today's date.


strFolder = "C:\Backups"
If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
strTodaysFile = "rmr" & Right("0" & Month(Date), 2) & Right("0" & Day(Date), 2) & Right(Year(Date), 2) & ".lmc"
strNewFileName = "oldfile.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFolder & strTodaysFile) = True Then
	If objFSO.FileExists(strFolder & strNewFileName) = True Then objFSO.DeleteFile strFolder & strNewFileName, True
	objFSO.MoveFile strFolder & strTodaysFile, strFolder & strNewFileName
	WScript.Echo "Cannot find " & strFolder & strTodaysFile
End If

Open in new window


Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

810 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