Void Funktion aus Header funktioniert nicht beim aufruf!HELP!



  • hi,
    ich habe mir eine header datei angelegt in der ich ein paar funktionen habe.
    funktion eins: such nach dateien in einem ordner und ADDED diese in einer listbox.

    funktion zwei: klickt man ein item der liste an wird fkt. zwei aktiv und soll die dateien zählen falls die ein ordner ist. aber irgendwie wird da überhaupt nix gezählt.

    hier mal der quelltext:

    [...]
            case WM_COMMAND: {
    
                switch( LOWORD( wParam ) ) {
    
                    case ID_BUTTON1: {
    
                        SendMessage( hEboxPath, WM_GETTEXT, 256, (long)szDirPath );
                        if( ScanDir( hListFiles, iFiles, szDirPath ) ) {
    
                            EnableWindow( hButtonScan, false );
                            EnableWindow( hButtonReset, true );
                        }
                        break;
                    }
    
                    case ID_BUTTON2: {
    
                        DoResetAll( hListFiles, iFiles );
                        EnableWindow( hButtonScan, true );
                        EnableWindow( hButtonReset, false );
                        break;
                    }
    
                    case ID_LIST1: {
    
                        switch( HIWORD( wParam ) ) {
    
                            case LBN_SELCHANGE: {
    
                                ScanCurrentItem( hListFiles, hEboxPath, szFname, 
                                                 szFsub, szFsize, szFtime,
                                                 szFused );
                                InvalidateRect( hWnd, 0, true );
                                break;
                            }
                        }
                    }
                    break;
                }
                return 0;
            }
    [...]
    

    die funktionen im header:

    bool ScanDir( HWND hListbox, int &index, char *szPath ) {
    
        HANDLE hFirstFile;
        WIN32_FIND_DATA wfd;
        char szBufferP[ 512 ];
            szBufferP[ 0 ] = 0;
        char szBufferP2[ 512 ];
            szBufferP2[ 0 ] = 0;
    
        if( *szPath == 0 ) {
    
            MessageBox( 0, "Enter a path, witch you want to scan!", "Warning!",
                        MB_OK | MB_ICONWARNING );
    
            return false;
        }
    
        strcat( szPath, "\\" );
        strcat( szBufferP2, szPath );
    
        hFirstFile = FindFirstFile( strcat( szPath, "*" ), &wfd );
        if( hFirstFile == INVALID_HANDLE_VALUE ) {
    
            MessageBox( 0, "Couldn't find any files, missmatch this path!", "Error!",
                        MB_OK | MB_ICONERROR );
            return false;
        }
    
        while( FindNextFile( hFirstFile, &wfd ) ) {
    
            strcat( szBufferP, szBufferP2 );
            strcat( szBufferP, wfd.cFileName );
            SendMessage( hListbox, LB_INSERTSTRING, index, (long)szBufferP );
            szBufferP[ 0 ] = 0;
            index++;
        }
        FindClose( hFirstFile );
    
        SendMessage( hListbox, LB_DELETESTRING, 0, 0 );
        return true;
    }
    
    void ScanCurrentItem( HWND hListbox, HWND hEdit, char *name, char *sub,
                          char *size, char *time, char *used ) {
    
        int index = -1;
        int iCount_sub = 0;
        char szBufferFile[ 256 ];
        HANDLE hFirstFile;
        WIN32_FIND_DATA wfd;
    
        szBufferFile[ 0 ] = 0;
    
        index = SendMessage( hListbox, LB_GETCURSEL, 0, 0 );
        SendMessage( hListbox, LB_GETTEXT, index, (long)szBufferFile );
        SendMessage( hEdit, WM_SETTEXT, 0, (long)szBufferFile );
    
        hFirstFile = FindFirstFile( szBufferFile, &wfd );
        if( hFirstFile == INVALID_HANDLE_VALUE ) {
    
            MessageBox( 0, "Couldn't find any files, missmatch this"
                           "path!", "Error!",
                        MB_OK | MB_ICONERROR );
            return;
        }
    
        while( FindNextFile( hFirstFile, &wfd ) ) {
    
            iCount_sub++;
        }
        FindClose( hFirstFile );
    
        szBufferFile[ 0 ] = 0;
        sprintf( szBufferFile, "%i", iCount_sub );
        MessageBox( 0, szBufferFile, "Count", MB_OK );
    }
    

    hoffe ihr könntet mir helfen.

    Gruß Tobi.



  • Siehe ganz unten (flenders's Beispiel): http://www.c-plusplus.net/forum/viewtopic-var-t-is-39396.html



    1. FindFirstFile/FindNextFile arbeitet nicht rekursiv
    2. Nach FindFirstFile hast du bereits das erste Ergebnis, deine Loops überspringen also immer das erste Ergebnis.


  • hmm sorry aber ich weis snet wie man das so schreibt das er mir die anzahl der im ordner befindlichen datein ausgibt... erzählt eine datei uznd da is schluss...





  • *argh!* rekursion... ich habs immer noch net ver standen xD... naja ich schau mal

    danke erst mal
    Gruß Tobi.



  • Gute Nachricht zuerst : Für Deine Aufgabenstellung brauchst Du keine Rekursion.

    T0bi schrieb:

    ... er zählt eine datei und da is schluss...

    Dem Aufruf von "FindFirstFile ()" in der Funktion "ScanCurrentItem ()" fehlt die "Wildcard" (\*) im Suchstring.
    Der Aufruf sollte so (oder so ähnlich) sein wie in der Funktion "ScanDir ()".



  • merker schrieb:

    Gute Nachricht zuerst : Für Deine Aufgabenstellung brauchst Du keine Rekursion.

    Klar, wenn er auch Unterordner erfassen will.



  • also ich habe mir jetzt erst mal versucht als konsolenanwendung ne test funktion zu schreiben:

    bool SearchFiles( char *szPath ) {
    
        HANDLE hFile;
        WIN32_FIND_DATA wfd;
        char szPathArg[ 1024 ];
    
        szPathArg[ 0 ] = 0;
        strcpy( szPath, "\\*" );
    
        hFile = FindFirstFile( szPath, &wfd );
        if( hFile == INVALID_HANDLE_VALUE ) {
    
            cerr << "\n ERROR: Miss match this path!\n" << endl;
            return false;
        }
    
        do {
    
            if( wfd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY ) {
    
                textcolor( YELLOW );
                cprintf( "\n Directory: " );
                cout << wfd.cFileName << endl;
    
                strcat( szPathArg, szPath );
                strcat( szPathArg, wfd.cFileName );
                strcat( szPathArg, "\\*" );
                SearchFiles( szPathArg );
            }
            else {
    
                textcolor( GREEN );
                cprintf( " File     : " );
                cout << wfd.cFileName << endl;
            }
    
        } while( FindNextFile( hFile, &wfd ) );
        FindClose( hFile );
    
        return true;
    }
    

    doch irgendwie ist da anscheinend Stack-Overflow und das prog schmiert ab. weiter springt die funktion auch nicht mehr aus dem dir raus.
    wo liegt mein fehler.

    Gruß Tobi.


Anmelden zum Antworten