I'm having trouble getting a loop involving the Dir(filepath, vbDirectory) to work cleanly. Problem is the "." and ".." results for the old DOS shortcut to current and parent directory. I can ignore those results just fine, but either I get caught in an infinite loop or get kicked out of the loop because the function won't move past this result. When I'm pulling folders, my function is copying files out of them, and when it's done I kill the empty folder. As long as it's only pulling subfolders, the code will move through each folder, do its work, and move to the next one until the folder is empty.
Any ideas for forcing the code to ignore the "." and ".." results when pulling folder names?
Thanks,
Tyler
Any ideas for forcing the code to ignore the "." and ".." results when pulling folder names?
Thanks,
Tyler
Code:
Public Function GetPictures()
Dim OrigLocation As String
Dim NewLocation As String
Dim Folder As String
Dim PicName As String
Dim AppendSQL As String
OrigLocation = "(filepath removed)"
NewLocation = "(filepath removed)"
Folder = Dir(OrigLocation, vbDirectory)
Do While Folder <> ""
If Folder <> "." And Folder <> ".." Then
'Make sure it's a directory
If (GetAttr(OrigLocation & Folder) And vbDirectory) = vbDirectory Then
PicName = Dir(OrigLocation & Folder & "/*.JPG")
Do While PicName <> ""
AppendSQL = "INSERT INTO [Picture Import Log] ( DateTaken, PictureName, DateImported, NewPath )" & _
"SELECT CDate(" & Folder & "), '" & PicName & "', Date(), '" & NewLocation & PicName & "';"
DoCmd.RunSQL AppendSQL
retval = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
retval = objFSO.CopyFile(OrigLocation & Folder & "\" & PicName, NewLocation & PicName, True)
Set objFSO = Nothing
Kill OrigLocation & Folder & "\" & PicName
PicName = Dir(OrigLocation & Folder & "/*.JPG")
Loop
RmDir OrigLocation & Folder & "\"
End If
End If
Folder = Dir(OrigLocation, vbDirectory)
Loop
End Function