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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Renaming text file - using wild character

Status
Not open for further replies.

arodri

Technical User
Jul 9, 2010
121
US
Hello,

I have the follwing code that I'm using to renam a text file, which works fine:
My.Computer.FileSystem.RenameFile("d:\FTP\Void\Unsubs\Test\CW_EmailUnsubs022912.txt", "EmailUnsubs.txt")


My problem is that the file that I need to rename ("CW_EmailUnsubs022912.txt") always has the date in the name, so the next day the file name will always be different. So today the name of the file will be "CW_EmailUnsubs030112.txt."


The first part of the file name will always be the same, the only thing that will change is the date. I need a script that will change the name of the file no matter what the date is, so I need to use a wildcard for the date part. I tried using an * "CW_EmailUnsubs*.txt" but it is invalid.

Any suggestions would be really appreciated!

Thanks!
 

So your file:[tt]
"CW_EmailUnsubs022912.txt" is renamed to "EmailUnsubs.txt"[/tt]
then you get a new file:[tt]
"CW_EmailUnsubs030112.txt" is renamed to "EmailUnsubs.txt"[/tt]

and the error happens, the file "EmailUnsubs.txt" already exists.


Have fun.

---- Andy
 

You can use the Date object with the Format function to get what you want:

Dim FileToRename As String

FileToRename = "CW_EmailUnsubs" & Format(Date.Today, "MMddyy") & ".txt"


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Andy- that's exactly what I need to do. I need the same set file name because I will be deleting every file as soon as its processed. There will be no duplicate names in the folder.

Jebenson- I can't have a date in the name. I just want the file name to be renamed to "Emailunsubs.txt" every time.

Thanks
 

arodri - you DO have a date in the file name:
arodri said:
always has the date in the name
CW_EmailUnsubs[red]022912[/red].txt

jebenson's sollution should work just fine.

Did you try it?

Have fun.

---- Andy
 
If you are just going to delete it, why bother renaming it first?
 
I need to rename it because I'm creating a dstx package with it and I need a set file name to map the columns in that file.

jebenson - that worked perfectly. I used a variation because the job will run before the current days file is in the folder, so I had to use -1 on the date, but other than that it's exactly what I needed.

Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top