Changing filenames in a folder

P

Pawan

Hello

have a folder with several files with different extensions. I want to
change exensions of ".cnf.xml" files to ".xls". I want to do this in excel
macro as I need to work on these files then. Is there any way to achieve this?

Thank you

Regards,
prm
 
J

joel

Change folder name as required.

Sub changeToXML()

Set fs = CreateObject("Scripting.FileSystemObject")

Folder = "c:\temp"

FName = Dir(Folder & "\" & "*.XML")
Do While FName <> ""
OldName = Folder & "\" & FName
'take old anem remove extension
NewName = Left(OldName, InStrRev(OldName, "."))
'add xls
NewName = NewName & "xls"

fs.MoveFile OlName, NewName

FName = Dir()
Loop

End Su
 
J

Jacob Skaria

Try the below

Sub Macro()
Dim strFile As String, strFolder As String
strFolder = "c:\"
strFile = Dir(strFolder & "*.cnf.xml", vbNormal)
Do While strFile <> ""
Name strFolder & strFile As strFolder & Replace(strFile, ".cnf.xml", ".xls")
strFile = Dir
Loop
End Sub

If this post helps click Yes
 
P

Pawan

Thanks Jacob.. It worked! :)

Jacob Skaria said:
Try the below

Sub Macro()
Dim strFile As String, strFolder As String
strFolder = "c:\"
strFile = Dir(strFolder & "*.cnf.xml", vbNormal)
Do While strFile <> ""
Name strFolder & strFile As strFolder & Replace(strFile, ".cnf.xml", ".xls")
strFile = Dir
Loop
End Sub

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top