Potresti anche usare un oggetto di tipo FileSystemObject: sulla guida in linea ci sono esempi belli chiari. Io ad esempio ho usato queste funzioncine:
codice:
Public Function Chk_Path(Cartella As String) As Boolean
Dim fso
Chk_Path = False
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists(Cartella) Then
Chk_Path = True
End If
Set fso = Nothing
End Function
Public Function ReadAllTextFile(nFile)
Const ForReading = 1, ForWriting = 2
Dim fso, f
On Error GoTo Err_Read
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(nFile, ForReading)
ReadAllTextFile = f.ReadAll
Exit Function
Err_Read:
ReadAllTextFile = ""
Me.Desc_Errore = Err.Description
End Function
Private Function EsisteFile(nFile) As Boolean
Dim fso, f
EsisteFile = False
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.fileexists(nFile) Then
EsisteFile = True
End If
Set fso = Nothing
End Function
oppure in altri contesti
codice:
......
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
fso.deletefile Path_Stampe & "stampa_pdf*.pdf", True
......
Dim filelist, filesingolo
Set filelist = fso.GetFolder(Path_Stampe).Files
For Each filesingolo In filelist
If UCase(Right(filesingolo.Name, 4)) = ".PDF" Then
MsgBox filesingolo.Name
End If
Next
Set fso = Nothing
......
Buon lavoro