PDA

View Full Version : OTTENERE IL PERCORSO DI UN FILE


CIUFFO
12-02-2003, 12:10
Mi servirebbe ottenere la stringa del percorso completo di un file.
In Vb di una maschera di access ad esempio vorrei ottenere il percorso del file .mdb corrente.
Ho provato con GetAbsolutePathName e GetCurrentDirectory, ma mi danno un percorso non completo.
Ponendo ad esempio un DB in: C:\Documents and Settings\Giovanni\documenti\Mia cartella\mio file.mdb il codice sotto mi dà: C:\Documents and Settings\Giovanni\documenti\mio file.mdb !
Perchè mi taglia \Mia cartella\ ?
Private Declare Function GetFullPathName Lib "kernel32" Alias "GetFullPathNameA" (ByVal lpFileName As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long
Private Sub Form_Load()
Dim Buffer As String, Ret As Long
'create a buffer
Buffer = Space(255)
'copy the current directory to the buffer and append 'myfile.ext'
Ret = GetFullPathName("mio file.Mdb", 255, Buffer, "")
'remove the unnecessary chr$(0)'s
Buffer = Left(Buffer, Ret)
'show the result
MsgBox Buffer
End Sub

tas
12-02-2003, 12:59
Non occorre che usi le API, basta questa funzione:
Public Function GetPathName(db As Database) As String
GetPathName = db.Properties("Name").Value
End Function

da usare così:
path = GetPathName(CurrentDB)
Nota: per usare questa funzione è necessario dichiarare, nella lista dei riferimenti (menu Strumenti/Riferimenti di VBA) la libreria Microsoft DAO 3.x

CIUFFO
13-02-2003, 16:37
grazie mille ;)