Home » U++ Library support » U++ Core » Dehaviour of DirectoryExists
|
|
Re: Dehaviour of DirectoryExists [message #44997 is a reply to message #44995] |
Wed, 12 August 2015 20:12 |
|
kov_serg
Messages: 37 Registered: August 2008 Location: Russia
|
Member |
|
|
I expected something like this
Windows:
#include <windows.h>
#include <stdio.h>
int is_dir(const char *szPath) {
DWORD dwAttrib = GetFileAttributesA(szPath);
return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
(dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
}
void test(const char* name) {
printf("is_dir=%d : %s\n",is_dir(name),name);
}
int main(int argc,char** argv) {
test("C:\\Windows");
test("C:\\Windows\\");
test("C:\\Windows\\.");
test("C:\\Windows\\.\\");
test("C:\\Windows\\none");
test("\\\\?\\C:\\Windows");
test("\\\\?\\C:\\Windows\\none");
return 0;
}
Output:
is_dir=1 : C:\Windows
is_dir=1 : C:\Windows\
is_dir=1 : C:\Windows\.
is_dir=1 : C:\Windows\.\
is_dir=0 : C:\Windows\none
is_dir=1 : \\?\C:\Windows
is_dir=0 : \\?\C:\Windows\none
Linux:
include <sys/stat.h>
#include <stdio.h>
int is_dir(const char* name) {
struct stat s;
int err = stat(name, &s);
if(-1 == err) return 0;
return S_ISDIR(s.st_mode) ? 1:0;
}
void test(const char* name) {
printf("is_dir=%d : %s\n",is_dir(name),name);
}
int main(int argc,char** argv) {
test("/home");
test("/home/");
test("/home/.");
test("/home/./");
test("/home/none");
return 0;
}
Output:
is_dir=1 : /home
is_dir=1 : /home/
is_dir=1 : /home/.
is_dir=1 : /home/./
is_dir=0 : /home/none
https://en.wikipedia.org/wiki/Principle_of_least_astonishmen t
[Updated on: Wed, 12 August 2015 20:14] Report message to a moderator
|
|
|
|
Goto Forum:
Current Time: Sun Sep 08 15:02:30 CEST 2024
Total time taken to generate the page: 0.01798 seconds
|