The following is an example of using the filesystemobject ref library to create some system objects and delete all of the PDF files in a given folder.
Code:
'Delete the PDF files in the temp folder
Dim strFile As String
strFile = "\\ServerName\FolderName\TempFolder"
Dim fsoFile As New FileSystemObject
Dim objFolder As Folder
Dim objFile As File
Set objFolder = fsoFile.GetFolder(strFile)
For Each objFile In objFolder.Files
If InStr(objFile.Name, ".PDF") Then 'locate a filename that contains .PDF in the name
objFile.Delete True 'Delete the file
End If
Next
Set objFolder = Nothing
'end 'Delete the PDF files in the temp folder
You can also use the filesystemobject to copy an entire directory. This may help to copy a folder located by the user via the filepicker to a temp folder. The idea of the temp folder is to loop through and delete. If you do not delete a file you will be in a perpetual loop. The other approach would be to enumerate the files and then go back through your enumerated list to import the files into your DB.
Here is some sample code to copy a folder.
Code:
Dim sourceFile As String, destinationFile As String
Dim aFSO As Object
sourceFile = "C:\Test\Sub1"
destinationFile = "C:Test\NewFolder"
Set aFSO = CreateObject("Scripting.FileSystemObject")
CopyFolder = False
aFSO.CopyFolder sourceFile, destinationFile
CopyFolder = True