General |
6.201 Dall'indirizzo completo di un file estrarre solo il nome del file |
Roberto, Alessandro Baraldi |
Con la funzione che segue si ottiene dall'indirizzo completo di un file solo il nome del file stesso. Public Function ParseFileName(ByVal FileName As String) As String '***************************************************************** 'Name : ParseFileName (Function) 'Purpose : Return File Name ONLY 'Author : Alessandro Baraldi 'E.Mail : ik2zok@libero.it 'Date : 23 gennaio 2002 '***************************************************************** On Error GoTo Err_ParseFileName ParseFileName = Right(FileName, Len(FileName) - InStrRev(FileName, "\")) 'ParseFileName = Dir(FileName) Exit_ParseFileName: Exit Function Err_ParseFileName: MsgBox Err.Description Resume Exit_ParseFileName End FunctionSe ad esempio l'indirizzo completo del file fosse C:\Programmi\DataBase.mdb, la funzione di cui sopra ritornerebbe la stringa DataBase.mdb. La funzione di cui sopra usa la funzione intrinseca InStrRev, che come si sa è disponibile sola dalla versione Access 2000. Coloro che usano Access 97 dovrenno registrare in un modulo del database anche la seguente funzione: Public Function InstrRev(ByVal buf As String, ByVal strToFind As String) As Integer Dim i As Integer Dim j As Integer Dim l As Integer If Len(strToFind) = 0 Or Len(buf) = 0 Then InstrRev = 0 Exit Function End If i = 1 j = 1 l = Len(strToFind) While i > 0 i = InStr(j, buf, strToFind) If i > 0 Then j = i + l Wend If j > 1 Then InstrRev = j - l Else InstrRev = 0 End If End Function |