Oppure

Loading
25/02/08 17:30
LuigiBiasi
in definitiva il codice dovrebbe essere cosi:

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
Dim o() As String
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
    o = Split(Files, "\")
    file(i) = o(UBound(o))
    i = i + 1
Next

For i = 0 To UBound(file)
If (file(i) = filename) Then
    'fai quello che vuoi
    tr = True
    Exit Function
End If
Next i
If tr = False Then
'ha continuato il For non ha trovato il file
For i = 0 To UBound(directory)
If (directory(i) = "") Then
Exit Function
End If
getfile directory(i), filename
Next i
Else
getfile = True 'esci dalla funzione positivamente
Exit Function
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:40
aaa
25/02/08 17:39
mi da sempre lo stesso problema

o ho messo nel formload

d = getfile("C:\", "ntoskrnl.exe";)

ma mi dice sempre:

CHiamata di routine o argomento nn valido

e mi evidenzia questo:

Set f = c.GetFolder(path)


Cos'è sono io che sbaglio qualcosa? tieni conto che è un nuovo progetto e c'è solo il form senza componenti...

fosse questo il problema?:-|:-|
25/02/08 17:41
LuigiBiasi
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
Dim o() As String
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
    o = Split(Files, "\")
    file(i) = o(UBound(o))
    i = i + 1
Next

For i = 0 To UBound(file)
If (file(i) = filename) Then
    'fai quello che vuoi
    tr = True
    Exit Function
End If
Next i
If tr = False Then
'ha continuato il For non ha trovato il file
For i = 0 To UBound(directory)
If (directory(i) = "") Then
Exit Function
End If
getfile directory(i), filename
Next i
Else
getfile = True 'esci dalla funzione positivamente
Exit Function
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



questo l'ho testato e funziona.
aaa
25/02/08 17:43
Postato originariamente da LuigiBiasi:

questo l'ho testato e funziona.


E allora è iella mia :(

indice non compreso nell'intervallo

file(i) = o(UBound(o))
25/02/08 17:44
LuigiBiasi
devi controllare il valore di path. e vedere se è giusto.
attenzione a mettere gli array molto grandi metti 100000.
aaa
25/02/08 17:45
LuigiBiasi
If (file(i) = filename) Then
'fai quello che vuoi
tr = True
Exit Function
End If

qui li dici di uscire se ha trovato tra i file quello uguale a filename
aaa
25/02/08 17:49
ho ingrandito l'array, ma il problema persiste...

inoltre:

If (file(i) = filename) Then
'fai quello che vuoi
tr = True
Exit Function
End If

dove lo metto? l'ho messo alla fine dell'end if precedente...

Grazie davvero 1000 per tutto l'aiuto e l'assistenza
25/02/08 17:50
LuigiBiasi
ho finito.
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(1000) As String
Dim directory(1000) As String
Dim i As Integer
Dim tr As Boolean
Dim o() As String
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
o = Split(Files, "\")
file(i) = o(UBound(o))
i = i + 1
Next

For i = 0 To UBound(file)
If (file(i) = filename) Then
'fai quello che vuoi
tr = True
getfile = True
Exit Function
End If
Next i
If tr = False Then
'ha continuato il For non ha trovato il file
For i = 0 To UBound(directory)
If (directory(i) = "") Then
Exit Function
End If
If (getfile(directory(i), filename) = True) Then
    getfile = True
    Exit Function
End If
Next i
Else
getfile = True 'esci dalla funzione positivamente
Exit Function
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



questo funziona perfettamente.
la funione restituisce true se il file esiste altrimenti false.

Ciao.
Ultima modifica effettuata da LuigiBiasi 25/02/08 17:51
aaa