Click here to Skip to main content
15,902,870 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Registry ??? Pin
vcplusplus30-Aug-03 0:59
vcplusplus30-Aug-03 0:59 
GeneralRe: Registry ??? Pin
dirand8530-Aug-03 3:07
dirand8530-Aug-03 3:07 
GeneralCircular rotating Buttons.. Pin
cutti29-Aug-03 21:45
cutti29-Aug-03 21:45 
GeneralRe: Circular rotating Buttons.. Pin
PJ Arends29-Aug-03 22:56
professionalPJ Arends29-Aug-03 22:56 
GeneralAbout Float Point Exception Pin
HansonDavid29-Aug-03 20:52
HansonDavid29-Aug-03 20:52 
GeneralPROJECTS Pin
Neelesh K J Jain29-Aug-03 18:49
Neelesh K J Jain29-Aug-03 18:49 
GeneralRe: PROJECTS Pin
TigerNinja_29-Aug-03 18:54
TigerNinja_29-Aug-03 18:54 
GeneralWinAPI FindNextFile problem Pin
TigerNinja_29-Aug-03 18:36
TigerNinja_29-Aug-03 18:36 
Hi All,
I can not seem to get ::FindNextFile to work properly, or should I say the way I would expect it to work. The code below is straight out of MSDN, but it only works on the first file, the FindNextFile call returns FALSE, thus it does not iterate through the entire directory. I have a ton of .txt files, so it should find more than one.

Thanks in advance for any help or suggestions ?

<br />
#include <windows.h><br />
#include <stdio.h><br />
<br />
WIN32_FIND_DATA FileData; <br />
HANDLE hSearch; <br />
DWORD dwAttrs; <br />
char szDirPath[] = "c:\\TEXTRO\\"; <br />
char szNewPath[MAX_PATH]; <br />
char szHome[MAX_PATH]; <br />
 <br />
BOOL fFinished = FALSE; <br />
 <br />
// Create a new directory. <br />
 <br />
if (!CreateDirectory(szDirPath, NULL)) <br />
{ <br />
    printf("Couldn't create new directory."); <br />
    return;<br />
} <br />
 <br />
// Start searching for .TXT files in the current directory. <br />
 <br />
hSearch = FindFirstFile("*.txt", &FileData); <br />
if (hSearch == INVALID_HANDLE_VALUE) <br />
{ <br />
    printf("No .TXT files found."); <br />
    return;<br />
} <br />
 <br />
// Copy each .TXT file to the new directory <br />
// and change it to read only, if not already. <br />
 <br />
while (!fFinished) <br />
{ <br />
    lstrcpy(szNewPath, szDirPath); <br />
    lstrcat(szNewPath, FileData.cFileName); <br />
    if (CopyFile(FileData.cFileName, szNewPath, FALSE))<br />
    { <br />
        dwAttrs = GetFileAttributes(FileData.cFileName); <br />
        if (!(dwAttrs & FILE_ATTRIBUTE_READONLY)) <br />
        { <br />
            SetFileAttributes(szNewPath, <br />
                dwAttrs | FILE_ATTRIBUTE_READONLY); <br />
        } <br />
    } <br />
    else <br />
    { <br />
        printf("Couldn't copy file."); <br />
        return;<br />
    } <br />
 <br />
    if (!FindNextFile(hSearch, &FileData)) <br />
    {<br />
        if (GetLastError() == ERROR_NO_MORE_FILES) <br />
        { <br />
            MessageBox(hwnd, "No more .TXT files.", <br />
                "Search completed.", MB_OK); <br />
            fFinished = TRUE; <br />
        } <br />
        else <br />
        { <br />
            printf("Couldn't find next file."); <br />
            return;<br />
        } <br />
    }<br />
} <br />
 <br />
// Close the search handle. <br />
 <br />
FindClose(hSearch);<br />






R.Bischoff
.NET, Kommst du mit?


GeneralRe: WinAPI FindNextFile problem Pin
Michael Dunn29-Aug-03 19:08
sitebuilderMichael Dunn29-Aug-03 19:08 
GeneralRe: WinAPI FindNextFile problem Pin
TigerNinja_29-Aug-03 19:27
TigerNinja_29-Aug-03 19:27 
GeneralRe: WinAPI FindNextFile problem Pin
TigerNinja_29-Aug-03 19:23
TigerNinja_29-Aug-03 19:23 
GeneralSolution of your IT/Computer science Problems Pin
mindnets29-Aug-03 17:44
mindnets29-Aug-03 17:44 
GeneralRe: Solution of your IT/Computer science Problems Pin
Taka Muraoka29-Aug-03 18:04
Taka Muraoka29-Aug-03 18:04 
GeneralRe: Solution of your IT/Computer science Problems Pin
l a u r e n29-Aug-03 18:19
l a u r e n29-Aug-03 18:19 
GeneralRe: Solution of your IT/Computer science Problems Pin
Ryan Binns29-Aug-03 22:13
Ryan Binns29-Aug-03 22:13 
GeneralNeed help on listbox functions Pin
coda_x29-Aug-03 14:39
coda_x29-Aug-03 14:39 
GeneralRe: Need help on listbox functions Pin
Larry J. Siddens29-Aug-03 15:00
Larry J. Siddens29-Aug-03 15:00 
GeneralRe: Need help on listbox functions Pin
coda_x29-Aug-03 15:21
coda_x29-Aug-03 15:21 
GeneralRe: Need help on listbox functions Pin
Michael Dunn29-Aug-03 15:40
sitebuilderMichael Dunn29-Aug-03 15:40 
GeneralRe: Need help on listbox functions Pin
coda_x29-Aug-03 15:57
coda_x29-Aug-03 15:57 
GeneralRe: Need help on listbox functions Pin
l a u r e n29-Aug-03 18:24
l a u r e n29-Aug-03 18:24 
GeneralRe: Need help on listbox functions Pin
Larry J. Siddens30-Aug-03 3:26
Larry J. Siddens30-Aug-03 3:26 
QuestionDoes MFC ship with IE or Windows? Pin
Shutter29-Aug-03 14:17
Shutter29-Aug-03 14:17 
AnswerRe: Does MFC ship with IE or Windows? Pin
Joe Woodbury29-Aug-03 18:49
professionalJoe Woodbury29-Aug-03 18:49 
GeneralProblem with a property sheet Pin
Artem Moroz29-Aug-03 12:55
Artem Moroz29-Aug-03 12:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.