Имя Файла по полному Пути или определённую чать (только название или только расширение).
Public Function GetFileNameByPath(varPath As Variant) As String
On Error GoTo GetFileNameByPath_Err
GetFileNameByPath = Mid(varPath, InStrRev(varPath, "\") + 1)
Exit Function
GetFileNameByPath_Err:
GetFileNameByPath = "GetFileNameByPath ERR#" & Err.Number
End Function
Может возвращаать не только имя файла, но и его определённую чать (только название или только расширение).
Public Function GetFileName(ByVal sPath As String, Optional NamePart As Integer = 0) As String
Dim sFileName As String
Dim iPos As Integer
On Error GoTo GetFileName_Err
iPos = InStrRev(sPath, "\")
sFileName = Mid(sPath, iPos + 1)
Select Case NamePart
Case 1
iPos = InStrRev(sFileName, ".")
sFileName = Mid(sFileName, 1, iPos - 1)
Case 2
iPos = InStrRev(sFileName, ".")
sFileName = Mid(sFileName, iPos + 1)
End Select
GetFileName = sFileName
GetFileName_Bye:
Exit Function
GetFileName_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
"in procedure GetFileName of Module modUtils", vbCritical, "Error!"
Resume GetFileName_Bye
End Function
Public Function OnlyName(path)
Dim File As String, Ext As String
With Access.WizHook
.Key = 51488399
.SplitPath path, vbNullString, vbNullString, File, Ext
End With
OnlyName = File & Ext
End Function
Имя существующего файла по полному пути
Public Function FileNameByPath(sPath As String) As String
Dim objFSO As Object
Dim objFile As Object
On Error GoTo FileNameByPath_Err
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(sPath)
FileNameByPath = objFile.Name
FileNameByPath_End:
On Error Resume Next
Err.Clear
Exit Function
FileNameByPath_Err:
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description & vbCrLf & _
"in Function: FileNameByPath in module: 00_Tests", vbCritical, "Error in Application"
Err.Clear
Resume FileNameByPath_End
End Function
|