Solved

FindFirstFileEx API ??

Posted on 1998-05-04
8
1,074 Views
Last Modified: 2012-06-21
FindFirstFileEx API ??

From Tim Brockway.   Email : BROCKWAYJT@AOL.COM
Version= VB5

PROBLEM DESCRIPTION.

I am having problems calling the FindFirstFileEx API from VB.  Does anyone have an example?

I have the SDK notes on FindFirstFileEx but am stumped on the FINDEX_INFO_LEVELS and FINDEX_SEARCH_OPS parameters. In C++ they are "Enumeration"s and I'm not clear how I implement this in calls from VB.

Any ideas ? Any thoughts would be most welcome.

Many thanks,
Tim
0
Comment
Question by:brockway
  • 4
  • 3
8 Comments
 
LVL 1

Expert Comment

by:flivauda
ID: 1438678
Not sure what exactly you are doing and why you dont want to use the file dialogs already set up, but, here is some code to find all the files in a directory:

Add this code to a module in your project:

------begin module code------
Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long

Public Const MAX_PATH = 260

Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type

Type WIN32_FIND_DATA
        dwFileAttributes As Long
        ftCreationTime As FILETIME
        ftLastAccessTime As FILETIME
        ftLastWriteTime As FILETIME
        nFileSizeHigh As Long
        nFileSizeLow As Long
        dwReserved0 As Long
        dwReserved1 As Long
        cFileName As String * MAX_PATH
        cAlternate As String * 14
End Type
------end module code------

I just added a listbox and a command button to my form to verify that this code works, so do that then add this code to the click event of your comand button:

---begin form code---
Private Sub Command1_Click()
    Dim fileInfo As WIN32_FIND_DATA
    Dim hFile As Long ' File handle
    Dim notFinished As Boolean
   
    hFile = FindFirstFile("c:\temp\*.*", fileInfo)
   
    notFinished = (h <> -1)
   
    Do While notFinished
        notFinished = FindNextFile(hFile, fileInfo)
        List1.AddItem fileInfo.cFileName
    Loop

End Sub

---end form code----

This code will read every file in my C:\temp directory adn add it to the list box list1.  what you do with it from here is up to you.
0
 

Author Comment

by:brockway
ID: 1438679
Nope sorry,

I'm already using the code you suggest for some work.

Observe that the question relates to the FindFirstFileEx api NOT FindFirstFile.

The native VB file handling routines will not serve because I need more
functionality than they provide.

Many thanks for you thoughts anyway.

Cordially,

Tim
0
 
LVL 5

Accepted Solution

by:
dirtdart earned 50 total points
ID: 1438680
First of all, do you realize that this call is NT specific, so your program won't work on 95?  Just a cautionary note.  With that in mind, unfortunatly, I can't get access to my NT machine, so I'm kind of shooting in the dark.  But here is what I came up with.

Public Const FINDX_INFO_STANDARD = 0
Public Const FINDX_INFO_MAX_LEVEL = 1
Public Const FINDX_SEARCH_NAME_MATCH = 0
Public Const FINDX_SEARCH_LIMIT_TO_DIRECTORIES = 1
Public Const FINDX_SEARCH_LIMIT_TO_DEVICES = 2
Public Const MAX_PATH = 255

Type FILETIME
        dwLowDateTime As Long
        dwHighDateTime As Long
End Type

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


Declare Function FindFirstFileEx Lib "kernel32" Alias "FindFirstFileExA" (ByVal lpFileName As String, FILE_INFO_LEVEL As Long, lpFindData As WIN32_FIND_DATA, FINDEX_SERACH_OPS As Long, lpSearchCriteria As Any, dwAdditionalFlags As Long) As Long

The enum types from c are just like enums in VB.  They don't have to be passed as enums, they can be passed as long values as specified by the constants above.
0
 

Author Comment

by:brockway
ID: 1438681
DirtDarts answer did not appear. Blank space only.

Am I missing something or was this a glitch?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:dirtdart
ID: 1438682
Well, don't know what happened, but luckily I saved the code.

Public Const FINDX_INFO_STANDARD = 0
Public Const FINDX_INFO_MAX_LEVEL = 1
Public Const FINDX_SEARCH_NAME_MATCH = 0
Public Const FINDX_SEARCH_LIMIT_TO_DIRECTORIES = 1
Public Const FINDX_SEARCH_LIMIT_TO_DEVICES = 2
Public Const MAX_PATH = 255

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


Declare Function FindFirstFileEx Lib "kernel32" Alias "FindFirstFileExA" (ByVal lpFileName As String, FILE_INFO_LEVEL As Long, lpFindData As WIN32_FIND_DATA, FINDEX_SERACH_OPS As Long, lpSearchCriteria As Any, dwAdditionalFlags As Long) As Long


Unfortunatly I don't have access to my NT box, so I can't test this, but the enumerations should work when passed as long values.  The constants are shown above.
0
 

Author Comment

by:brockway
ID: 1438683
Dear DirtDart,

Are you saying that the FindFirstFileEx API will work only on NT?

( You said "Unfortunatly I don't have access to my NT box, so I can't test this, but the enumerations should work when passed as long values".)

I should have made it clear I am Win 95.?

Many many thanks for the info. Look forward to reply if you have moment.

Cordially,

Tim.
0
 
LVL 5

Expert Comment

by:dirtdart
ID: 1438684
That is correct.  The FindFirstFileEx API is only available in NT.
0
 

Author Comment

by:brockway
ID: 1438685
Thankyou.

Please accept the points.

Cordially Tim.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now