Title: RE: [MI-L] testing attribute of directory

Martin,

You can use this function to question a "file Attribute" to see if it is a directory

Define MAX_PATH                                         260
Define FILE_ATTRIBUTE_DIRECTORY &H10            '16     The file is a directory.

Type WIN32_FIND_DATA
        dwFileAttributes        As Integer
        ftCreationTime  As FILETIME
        ftLastAccessTime        As FILETIME
        ftLastWriteTime As FILETIME
        nFileSizeHigh   As Integer
        nFileSizeLow    As Integer
        dwReserved0             As Integer
        dwReserved1             As Integer
        cFileName               As String * MAX_PATH
        cAlternate              As String * 14
End Type

'**********************************************************************************************''
'Determinating whether a file is a directory by it fileattributes
'**********************************************************************************************''
Function APIFileAttributeIsDirectory(ByVal nFileAttributes As Integer) As Logical

OnError GoTo ErrorOccured

APIFileAttributeIsDirectory = FALSE

        If (nFileAttributes /  2 ^ FILE_ATTRIBUTE_DIRECTORY_BIT) Mod 2 Then
                APIFileAttributeIsDirectory = TRUE
        End If

        Exit Function
'-------------------------
ErrorOccured:
        Note ERR_ERRORMSG & lf & Error$()

End Function

You would use this in the loop where you have access to the WIN32_FIND_DATA structure. The loop could look like this:


Dim     f As WIN32_FIND_DATA
        ...

        hFindFile = FindFirstFile (sPath + sFilespec, f)
        If hFindFile <> INVALID_HANDLE_VALUE Then
                Do
'                       Print "Found file: " & f.cFilename & ", " & f.dwFileAttributes
                        If APIFileAttributeIsDirectory(f.dwFileAttributes) Then
                                'This is a directory
                        Else
                                'This is not a directory
                        End if
                        nStatus = FindNextFile (hFindFile, f)

                Loop While nStatus = 1
        End If

HTH,

Peter Horsbøll Møller
GIS Developer, MTM
Geographical Information & IT
 
COWI A/S
Odensevej 95
DK-5260 Odense S.
Denmark
 
Tel     +45 6311 4900
Direct  +45 6311 4908
Mob     +45 5156 1045
Fax     +45 6311 4949
E-mail  [EMAIL PROTECTED]
http://www.cowi.dk/gis

"For enden af regnbuen..." - hvordan kommer man dertil og er det overhovedet muligt?
Læs mere om årets MapInfo konference på www.cowi.dk/mapinfokonference

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Martin Hodder

Sent: Thursday, September 21, 2006 9:13 PM
To: Mapinfo-L@lists.directionsmag.com
Subject: [MI-L] testing attribute of directory

Hi,

I was wondering if anyone can help me before I delve into the windows API.

I have the API call to get a list of files from a folder.

I now need to scan these files and see if any of then are actually folders and not files.

Does anyone know hoe to do this?

Thanks

Martin



_______________________________________________
MapInfo-L mailing list
MapInfo-L@lists.directionsmag.com
http://www.directionsmag.com/mailman/listinfo/mapinfo-l



_______________________________________________
MapInfo-L mailing list
MapInfo-L@lists.directionsmag.com
http://www.directionsmag.com/mailman/listinfo/mapinfo-l

Reply via email to