Stilllegung des Forums
Das Forum wurde am 05.06.2023 nach über 20 Jahren stillgelegt (weitere Informationen und ein kleiner Rückblick).
Registrierungen, Anmeldungen und Postings sind nicht mehr möglich. Öffentliche Inhalte sind weiterhin zugänglich.
Das Team von spieleprogrammierer.de bedankt sich bei der Community für die vielen schönen Jahre.
Wenn du eine deutschsprachige Spieleentwickler-Community suchst, schau doch mal im Discord und auf ZFX vorbei!
Werbeanzeige
C-/C++-Quelltext |
|
1 2 |
File f = new File("C:/Test"); String[] files = f.list(); |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
void lsdir(const char *path, Array<String> &results) { WIN32_FIND_DATA fdata; HANDLE dhandle; // must append \* to the path { char buf[MAX_PATH]; snprintf(buf, sizeof(buf), "%s\\*", path); if((dhandle = FindFirstFile(buf, &fdata)) == INVALID_HANDLE_VALUE) { throw Error("FindFirstFile"); } } // even an "empty" directory will give two results - . and .. results.append(String(fdata.cFileName)); while(1) { if(FindNextFile(dhandle, &fdata)) { results.append(String(fdata.cFileName)); } else { if(GetLastError() == ERROR_NO_MORE_FILES) { break; } else { FindClose(dhandle); throw Error("FindNextFile"); } } } if(FindClose(dhandle) == 0) { throw Error("FindClose"); } } |
Quellcode |
|
1 2 3 4 5 6 7 |
F:\C++ Projekte\DoctorDangerous_ProfileSelector\ProfileSelectorGUI.hpp||In function 'void dir(std::string)':| F:\C++ Projekte\DoctorDangerous_ProfileSelector\ProfileSelectorGUI.hpp|66|error: 'snprintf' was not declared in this scope| F:\C++ Projekte\DoctorDangerous_ProfileSelector\ProfileSelectorGUI.hpp|68|error: 'Error' was not declared in this scope| F:\C++ Projekte\DoctorDangerous_ProfileSelector\ProfileSelectorGUI.hpp|73|error: 'String' was not declared in this scope| F:\C++ Projekte\DoctorDangerous_ProfileSelector\ProfileSelectorGUI.hpp|83|error: 'Error' was not declared in this scope| F:\C++ Projekte\DoctorDangerous_ProfileSelector\ProfileSelectorGUI.hpp|89|error: 'Error' was not declared in this scope| ||=== Build finished: 9 errors, 0 warnings ===| |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
void ProfileSelectorGUI::dir(string path) { WIN32_FIND_DATA fdata; HANDLE dhandle; // must append \* to the path { char buf[MAX_PATH]; snprintf(buf, sizeof(buf), "%s\\*", path.c_str()); if((dhandle = FindFirstFile(buf, &fdata)) == INVALID_HANDLE_VALUE) { ; } } // even an "empty" directory will give two results - . and .. profiles.push_back((fdata.cFileName)); while(true) { if(FindNextFile(dhandle, &fdata)) { profiles.push_back((fdata.cFileName)); } else { if(GetLastError() == ERROR_NO_MORE_FILES) { break; } else { FindClose(dhandle); } } } if(FindClose(dhandle) == 0) { ; } } |
C-/C++-Quelltext |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
#include <stdafx.h> int ListFiles(char *Dir){ HANDLE hFile; LPWIN32_FIND_DATA File; File = new _WIN32_FIND_DATAA; char *sDir = new char[1024]; strncpy(sDir, Dir, 1024); strcat(sDir, "*.*"); // Erste Datei suchen hFile = FindFirstFile(sDir, File); //Alle Dateien in diesem Ordner durchgehen do{ // Falls die Datei "." oder ".." heißt, eifach überspringen, da die // zu den übergeorndeten Ordnern führen if(!strcmp(File->cFileName, ".") || !strcmp(File->cFileName, "..")){ continue; } // Falls die Datei kein Ordner ist, zur Liste hinzufügen if(!(File->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)){ // Hinzufügen printf("%s\n", File->cFileName); } } while(FindNextFile(hFile, File)); //Alle Dateien in diesem Ornder durchgehen... } |
Deine Funktion ist vom Typ int, doch du machst nie eine Rückgabe (return)
Werbeanzeige