Re: [Dev-C++] List files and check if a directory exist.
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <we...@ha...> - 2002-10-10 12:11:50
|
Hi Guys,
Thkz Matthias.
I had test the code that u sent:
#include <stdio.h>
#include <dirent.h>
int fl_filename_isdir(const char* n);
int main(){
fl_filename_isdir("c:\\winnt");
return(0);
}
int fl_filename_isdir(const char* n) {
struct stat s;
#ifdef WIN32
char fn[1024];
int length;
// This workaround brought to you by the fine folks at Microsoft!
// (read lots of sarcasm in that...)
length = strlen(n);
if (length < (int)(sizeof(fn) - 1)) {
if (length < 4 && isalpha(n[0]) && n[1] == ':' &&
(isdirsep(n[2]) || !n[2])) {
// Always use D:/ for drive letters
fn[0] = n[0];
strcpy(fn + 1, ":/");
n = fn;
} else if (length > 0 && isdirsep(n[length - 1])) {
// Strip trailing slash from name...
length --;
memcpy(fn, n, length);
fn[length] = '\0';
n = fn;
}
}
#endif
return !stat(n, &s) && (s.st_mode&0170000)==0040000;
}
But it gave-me errors:
Executing g++.exe...
g++.exe "C:\tmp\test.cpp" -o
C:\tmp\test.exe" -s -I"E:\dev-c++\Dev-Cpp\include" -I"E:\dev-c++\Dev-Cpp
\include\g++-3" -I"E:\dev-c++\Dev-Cpp\include" -L"E:\dev-c++\Dev-Cpp\lib"
C:\tmp\test.cpp: In function `int fl_filename_isdir(const char *)':
C:\tmp\test.cpp:15: aggregate `struct stat s' has incomplete type and cannot
be initialized
C:\tmp\test.cpp:24: implicit declaration of function `int isalpha(...)'
C:\tmp\test.cpp:25: implicit declaration of function `int isdirsep(...)'
C:\tmp\test.cpp:40: type `stat' is not yet defined
Execution terminated
This stat and this code work under windows ??
I'm under windows. :)
Thkz a lot.
Best Regards.
[ ]'s
|