Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 953303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:01:56+00:00 2026-05-16T00:01:56+00:00

im using WIN32_FIND_DATA to store the data findfirstfile outputs. i want the file location

  • 0

im using WIN32_FIND_DATA to store the data findfirstfile outputs. i want the file location (C:\file) as a string but i don’t know how to get it or any other data from it.

Edit: here is my code

PTSTR pszFileName; 
PTSTR pszFileName2[100];
if (search_handle) 
{ 
    do 
    {
        pszFileName = file.cFileName;
        pszFileName2[loop] = pszFileName;
        Sleep(100);
        loop++;

        std::wcout << file.cFileName << std::endl;
    }
    while(FindNextFile(search_handle,&file)); 

    CloseHandle(search_handle); 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T00:01:56+00:00Added an answer on May 16, 2026 at 12:01 am

    WIN32_FIND_DATA is a struct. Check out the cFileName member.

    For example:

    WIN32_FIND_DATA FindData = {0};
    HANDLE hFind = FindFirstFile(pszPattern, &FindData);
    
    if (hFind != INVALID_HANDLE_VALUE)
    {
       do
       {
          PTSTR pszFileName = FindData.cFileName;
    
          // TODO: Use pszFileName in some way...
    
       } while (FindNextFile(hFind, &FindData));
    
       FindClose(hFind);
    }
    

    Update in response to comments

    In this example the storage for the string is on the stack, and the same buffer is used for every call. This means that every FindNextFile() overwrites the previous string. You will have to make a copy of the string.

    Since you’re using C++ and classes in std I suggest you store it in std::string (or better yet, make sure you define UNICODE and _UNICODE and use wstring.) Initializing a new string class will do the allocation and copying on your behalf.

    Alternatively you can copy the string using the typical C techniques (for example: using malloc + memcpy, strdup, or similar), but it sounds like you might want a refresher in strings, pointers, and memory allocation in C before you get to that.

    By the way — to check for error, your code compares the find handle against NULL; this is incorrect. FindFirstFile() returns INVALID_HANDLE_VALUE (which works out to (HANDLE)-1) on failure. Additionally, to close the handle you will want to use FindClose(), and not CloseHandle(). (A “find handle” isn’t really a handle to a kernel object in the same sense that a file handle, handle to a module, or a thread or process handle is. They’ve just overloaded the type.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using VB6 and the Win32 API to write data to a file,
Using the Win32 API (in C, but that's inconsequential), how can I tell if
I using the Win32 API and C/C++. I have a HFONT and want to
I know how to open a window with openGL (using Win32 or other toolkits).
Using Win32-specific APIs, is there an easy way to start an external application to
I have created a minidump using win32 api [DllImport(DbgHelp.dll, SetLastError = true)] private static
Note: Using raw Win32 CreateTheard() API No MFC An interface is simply a pointer
I'm using the Win32 CreateProcess function to perform a call to an external executable.
How do I remove a USB drive using the Win32 API? I do a
Using the standard win32 api, what's the best way to detect more than one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.