31/08/10 20:28
Berto
Avrei bisogno di un aiuto per conoscere il percorso di un file, per esempio prova.txt e poterlo inserire in una variabile. Ho controllato sul sito e ho trovato solo una discussione in vb.net e io non sono abbastanza esperto per tradurla in visual basic 6. Su google non sono riuscito a ottenere nulla, anche estendendo il campo di ricerca all'inglese, tranne che un algoritmo di cui capisco a malapena tre righe ma che forse potrebbe essere più comprensibile a programmatori esperti e risolvere il problema.
Chissà cosa diavolo ho postato? Non prendetevela se è un virus, ok?
Tornando seri, non ho idea di come fare. In teoria si potrebbe utilizzare la velocità di calcolo del pc per scansire tutto l'hard disk con un metodo try and error ma non so fare neanche quello. Se esistono delle funzioni o dei comandi in visual basic 6 possono essere una risposta più elegante ma ogni aiuto sarebbe comunque molto gradito.
Vi ringrazio in anticipo per le risposte, non è un problema urgente.
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long Private Declare Function SearchTreeForFile Lib "imagehlp" (ByVal RootPath As String, ByVal InputPathName As String, ByVal OutputPathBuffer As String) As Long Public Function SearchAllDrives(pstrFile As String) As String Dim i As Long Dim strDrives() As String Dim strMatch As String For i = 1 To EnumerateDrives(strDrives) strMatch = SearchDriveForFile(pstrFile, strDrives(i)) If Len(strMatch) <> 0 Then SearchAllDrives = strMatch Exit Function End If Next End Function Public Function EnumerateDrives(pstrDrives() As String) As Long Dim i As Long Dim strBuffer As String Dim strDrive As String ReDim pstrDrives(1 To 1) strBuffer = Space$(255) strBuffer = Left$(strBuffer, GetLogicalDriveStrings(255, ByVal strBuffer)) Do While InStr(strBuffer, "") strDrive = Left$(strBuffer, InStr(strBuffer, "") - 1) i = i + 1 ReDim Preserve pstrDrives(1 To i) pstrDrives(i) = strDrive strBuffer = Mid$(strBuffer, Len(strDrive) + 3) Loop If pstrDrives(1) = "" Then Erase pstrDrives EnumerateDrives = 0 Else: EnumerateDrives = i End If End Function Public Function SearchDriveForFile(pstrFile As String, Optional ByVal pstrDrive As String = "C:") As String Const MAX_PATH = 260 Dim strPath As String Dim lngReturn As Long strPath = String(MAX_PATH, 0) pstrDrive = Left$(pstrDrive, 1) & ":" If SearchTreeForFile(pstrDrive, pstrFile, strPath) <> 0 Then SearchDriveForFile = Left$(strPath, InStr(1, strPath, Chr$(0)) - 1) End Function
Chissà cosa diavolo ho postato? Non prendetevela se è un virus, ok?
Tornando seri, non ho idea di come fare. In teoria si potrebbe utilizzare la velocità di calcolo del pc per scansire tutto l'hard disk con un metodo try and error ma non so fare neanche quello. Se esistono delle funzioni o dei comandi in visual basic 6 possono essere una risposta più elegante ma ogni aiuto sarebbe comunque molto gradito.
Vi ringrazio in anticipo per le risposte, non è un problema urgente.
aaa