Oppure

Loading
25/02/08 17:07
LuigiBiasi
ti ho scritto proprio adesso il codice:


Dim c As New FileSystemObject


Dim dirve(10) As String
Private Sub Form_Load()


getfile "C:\", "prova.txt"
End Sub

Public Function getfile(path As String, filename As String) As Boolean
Dim f As Folder
Set f = c.GetFolder(path)
Dim file(100) As String
Dim directory(100) As String
Dim i As Integer
Dim tr As Boolean
tr = False
i = 0
For Each Folder In f.SubFolders
   directory(i) = path & Folder & "\"
    i = i + 1
Next
i = 0
For Each Files In f.Files
    file(i) = Files
    i = i + 1
Next

For i = 0 To UBound(file)
If (file(i) = filename) Then
    'fai quello che vuoi
    tr = True
End If
Next i
If tr = False Then
'ha continuato il for non ha trovato il file
For i = 0 To UBound(directory)
getfile directory(i), filename
Next i
Else
getfile = True 'esci dalla funzione positivamente
End If

End Function

Function getdrive(drive As String) As Boolean
    If (c.DriveExists(drive)) Then
    'il drive esiste
    getdrive = True
    End If
    
    getdrive = False
End Function




testalo non so se funziona perchè non ho avuto il tempo di provarlo.

questo oggetto è molto più flessibile delle dir o file listbox.

ed è molto intuitivo.
Ultima modifica effettuata da LuigiBiasi 25/02/08 17:16
aaa
25/02/08 17:14
mi da errore dicendo:

Tipo non corrispondente

e mi segnala

For i = 0 To UBound(direcotry)


:-|:-|:-|
25/02/08 17:17
LuigiBiasi
Postato originariamente da .:ViRuS:.:

mi da errore dicendo:

Tipo non corrispondente

e mi segnala

For i = 0 To UBound(direcotry)


:-|:-|:-|


perchè è directory e non direcotry

guarda il nome dell'array.

Dim c As New FileSystemObject


Dim dirve(10) As String
Private Sub Form_Load()


d = getfile("C:\", "prova.txt")
End Sub

Public Function getfile(path As String, filename As String) As Boolean
Dim f As Folder
Set f = c.GetFolder(path)
Dim file(100) As String
Dim directory(100) As String
Dim i As Integer
Dim tr As Boolean
tr = False
i = 0
For Each Folder In f.SubFolders
    directory(i) =  Folder
    i = i + 1
Next
i = 0
For Each Files In f.Files
    file(i) = Files
    i = i + 1
Next

For i = 0 To UBound(file)
If (file(i) = filename) Then
    'fai quello che vuoi
    tr = True
End If
Next i
If tr = False Then
'ha continuato il for non ha trovato il file
For i = 0 To UBound(directory)
getfile directory(i), filename
Next i
Else
getfile = True 'esci dalla funzione positivamente
End If

End Function

Function getdrive(drive As String) As Boolean
    If (c.DriveExists(drive)) Then
    'il drive esiste
    getdrive = True
    End If
    
    getdrive = False
End Function



Ultima modifica effettuata da LuigiBiasi 25/02/08 17:20
aaa
25/02/08 17:19
Chiamata di routine o argomento non valido:

Set f = c.GetFolder(path)
25/02/08 17:21
LuigiBiasi
Postato originariamente da .:ViRuS:.:

Chiamata di routine o argomento non valido:

Set f = c.GetFolder(path)


scrivi cosi
For Each Folder In f.SubFolders
directory(i) = Folder
i = i + 1
Next

al posto di

For Each Folder In f.SubFolders
directory(i) = path & Folder
i = i + 1
Next
aaa
25/02/08 17:25
stava gia...

:-|
25/02/08 17:25
LuigiBiasi
l'ultima parte va corretta cosi:

For i = 0 To UBound(directory)
If directory(i) = "" Then
exit funtion
End If
getfile directory(i), filename
Next i
Else
getfile = True 'esci dalla funzione positivamente
End If

ho commesso un sacco di errori.adesso che lo sto testando me ne sto accorgendo!!!
Ultima modifica effettuata da LuigiBiasi 25/02/08 17:26
aaa
25/02/08 17:28
ci vuole un IF.. dove lo metto?


Errori? Bah tieni conto che io ste cose non le so... non ti preoccupare per niente proprio...

anzi scusami pure per il disturbo.. dovrei impararle certe cose :-|:-|