|
|
Замена расширения файла (с переименованием)
Private Sub ChangeFileExt_Demo()
Dim sFilePath$, sFilePathNewExt$
sFilePath = "d:\Temp\FileNameToChangeExtension.txt"
If Dir(sFilePath) = "" Then
MsgBox "Файл :" & vbCrLf & sFilePath & vbCrLf & "не найден!", vbExclamation, "Stop!"
Exit Sub
End If
sFilePathNewExt = Mid(sFilePath, 1, InStrRev(sFilePath, ".")) & "csv"
Name sFilePath As sFilePathNewExt
End Sub
Вариант с FileSystemObject
Private Sub ChangeFileExt_Demo02()
Dim sFilePath$, sNewFileNameExt$
Dim objFSO As Object
sFilePath = "d:\Temp\FileNameToChangeExtension.txt"
If Dir(sFilePath) = "" Then
MsgBox "Файл :" & vbCrLf & sFilePath & vbCrLf & "не найден!", vbExclamation, "Stop!"
Exit Sub
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
sNewFileNameExt = objFSO.GetBaseName(sFilePath) & ".csv"
objFSO.GetFile(sFilePath).Name = sNewFileNameExt
Set objFSO = Nothing
End Sub
|
|