Rename Files

SDSU_Jim

Board Regular
Joined
Nov 29, 2005
Messages
127
I have created a macro that opens a *.TXT file, reformats it and saves a *.CSV file. I need to delete the original *.txt file and rename the *.CSV file to the "TXT name. I can delete the "txt" file with the "Kill" command, because I can use the wildcard "*" in the Kill command. I need to use the wildcard because the names of the file will vary. But I can't use the wildcard in the "Filecopy" command. I was looking to "Kill" the "Txt" file, "filecopy" the "CSV" file to a "txt" file then "kill" the "CSV" file. Since I can't use a wildcard and the name will be unknown until the operation takes place, anyone have any ideas??

THANKS
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(C:\myFiles\myOldFile.csv)

f.Name = "yourNewName"
 
Upvote 0
Joe Was said:
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(C:\myFiles\myOldFile.csv)

f.Name = "yourNewName"

But can you use a wildcard so "Unknown.CSV" gets renamed to "Unknown.TXT"??

The location the files are being uploaded to requires CSV files to have the "TXT" extention. I'm trying to eliminate someone having to do this by hand.

If this can't be done is there a way to save in the CSV format, but force the "TXT" extension??
 
Upvote 0
I know it's been a while, but I thought I'd follow up. My solution was to create a batch file ".bat" that could use a wild card and "shell" it within my macro. Anyway, thanks to those who took the time to help.[/i]
 
Upvote 0

Forum statistics

Threads
1,214,596
Messages
6,120,438
Members
448,966
Latest member
DannyC96

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top