Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

FindFirstFileEx API ??

Posted on 1998-05-04
8
1,105 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

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

Am I missing something or was this a glitch?
0
 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

860 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