D Paste by Anonymous
Description: None
Hide line numbers

Create new paste
Post a reply
View replies

Paste:
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  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
import std.stdio: writefln;
import std.file: exists;
import std.path: isabs;

/**
    File structure (create it so if you don't have it):

    Current dir:
    main.exe (our program)
    test-rel (dir or file, doesn't matter)

    Root (C:):
    test-abs (dir/file)
*/
void checkdir(char[] file)
{
    if(isabs(file))
        writefln("%s is reported as absolute", file);
    else
        writefln("%s is reported as relative", file);

    if(exists(file))
        writefln("%s FOUND", file);
    else
        writefln("%s NOT FOUND", file);

    writefln();
}

void main()
{
    writefln("FILE ./test-rel");
    checkdir(r"/test-rel"); // NOT FOUND
    checkdir(r"\test-rel"); // NOT FOUND

    writefln("FILE C:/test-abs");
    checkdir(r"/test-abs"); // FOUND
    checkdir(r"\test-abs"); // FOUND
}
/**
Output:
    FILE ./test-rel
    /test-rel is reported as relative
    /test-rel NOT FOUND

    \test-rel is reported as relative
    \test-rel NOT FOUND

    FILE C:/test-abs
    /test-abs is reported as relative
    /test-abs FOUND

    \test-abs is reported as relative
    \test-abs FOUND
*/

Replies:

    (some replies deleted)