Movian
11-09-2012, 05:59 AM
Hey,
I have a function to return a variant array of file names when passed a folder. This works fine in most instances however i am building a secondary system to work with the main system and when i use the exact same setup in this DB i get an error 13
The function being called is GetAllFilesInDir , after that i show how i am using it. All the variables are correct, tried all the trouble shooting i can think of... hope you guys have an idea!!
Public Function GetAllFilesInDir(strDirPath As String, Optional Extension As Variant) As Variant
' Loop through the directory specified in strDirPath and save each
' file name in an array, then return that array to the calling
' procedure.
' Return False if strDirPath is not a valid directory.
Dim strTempName As String, bugnum As Integer, varFiles() As Variant, lngFileCount As Long
' Make sure that strDirPath ends with a "\" character.
If Right$(strDirPath, 1) <> "\" Then
strDirPath = strDirPath & "\"
End If
' Make sure strDirPath is a directory.
If GetAttr(strDirPath) = vbDirectory Then
strTempName = Dir(strDirPath, vbDirectory)
Do Until Len(strTempName) = 0
' Exclude ".", "..".
If (strTempName <> ".") And (strTempName <> "..") Then
' Make sure we do not have a sub-directory name.
If (GetAttr(strDirPath & strTempName) _
And vbDirectory) <> vbDirectory Then
' Increase the size of the array
' to accommodate the found filename
' and add the filename to the array.
If IsMissing(Extension) Then
ReDim Preserve varFiles(lngFileCount)
varFiles(lngFileCount) = strTempName
lngFileCount = lngFileCount + 1
Else
If Right(strTempName, 3) = Extension Then
ReDim Preserve varFiles(lngFileCount)
varFiles(lngFileCount) = strTempName
lngFileCount = lngFileCount + 1
End If
End If
End If
End If
' Use the Dir function to find the next filename.
strTempName = Dir()
Loop
' Return the array of found files.
GetAllFilesInDir = varFiles
End If
GetAllFiles_End:
Exit Function
End Function
this is the code generating the error. I am using Option Explicit
Dim DataFile() as variant, loc as string
loc = CStr(GetSetting("Outputloc") & "\")
DataFile() = GetAllFilesInDir(loc)
~EDIT~
Looks like it MAY be caused by windows 8.... GetATTR seems to be returning 8208 instead of the expected 16 for a folder..... trying to look into this further. But if anyone has any more info on this, would be appreciated. Just want to make sure its a folder that's being looked through.
I have a function to return a variant array of file names when passed a folder. This works fine in most instances however i am building a secondary system to work with the main system and when i use the exact same setup in this DB i get an error 13
The function being called is GetAllFilesInDir , after that i show how i am using it. All the variables are correct, tried all the trouble shooting i can think of... hope you guys have an idea!!
Public Function GetAllFilesInDir(strDirPath As String, Optional Extension As Variant) As Variant
' Loop through the directory specified in strDirPath and save each
' file name in an array, then return that array to the calling
' procedure.
' Return False if strDirPath is not a valid directory.
Dim strTempName As String, bugnum As Integer, varFiles() As Variant, lngFileCount As Long
' Make sure that strDirPath ends with a "\" character.
If Right$(strDirPath, 1) <> "\" Then
strDirPath = strDirPath & "\"
End If
' Make sure strDirPath is a directory.
If GetAttr(strDirPath) = vbDirectory Then
strTempName = Dir(strDirPath, vbDirectory)
Do Until Len(strTempName) = 0
' Exclude ".", "..".
If (strTempName <> ".") And (strTempName <> "..") Then
' Make sure we do not have a sub-directory name.
If (GetAttr(strDirPath & strTempName) _
And vbDirectory) <> vbDirectory Then
' Increase the size of the array
' to accommodate the found filename
' and add the filename to the array.
If IsMissing(Extension) Then
ReDim Preserve varFiles(lngFileCount)
varFiles(lngFileCount) = strTempName
lngFileCount = lngFileCount + 1
Else
If Right(strTempName, 3) = Extension Then
ReDim Preserve varFiles(lngFileCount)
varFiles(lngFileCount) = strTempName
lngFileCount = lngFileCount + 1
End If
End If
End If
End If
' Use the Dir function to find the next filename.
strTempName = Dir()
Loop
' Return the array of found files.
GetAllFilesInDir = varFiles
End If
GetAllFiles_End:
Exit Function
End Function
this is the code generating the error. I am using Option Explicit
Dim DataFile() as variant, loc as string
loc = CStr(GetSetting("Outputloc") & "\")
DataFile() = GetAllFilesInDir(loc)
~EDIT~
Looks like it MAY be caused by windows 8.... GetATTR seems to be returning 8208 instead of the expected 16 for a folder..... trying to look into this further. But if anyone has any more info on this, would be appreciated. Just want to make sure its a folder that's being looked through.