Hey,
this might as well be a "Blame the manual", but it had me confused for a while.
When passing a filename including a relative folder, file_exists reports the file as existing even if it does not actually exist there, but in the main folder.
For example, say you have the file "onlyhere.txt" in your mainfolder, and a folder called "folder" that does
not have a file "onlyhere.txt".
To summarize, a "test.dat" no exists in both folders, "doesnotexist.dat" exists in no folders, and "onlyinsub.dat" exists only in the subfolder, (but no the main folder) whereas "onlyhere.dat" exists only in the main folder (but not the subfolder).Then
if(file_exists("onlyhere.txt"))
fires as expected, but so does
if(file_exists("folder\\onlyhere.txt"))
and that is not what I expected.
What
exactly does file_exists return when a file, well, exists? Is there a dependance on subfolders, even if that folder is given in the filename?
Because the following condition does not fire:
if(file_exists("onlyhere.txt")==1)
which is contrary to what I'd have expected from the manual.
-----
CODE FOR TESTINGYou'll need to setup and create a few dummyfiles.
Put "test.dat" and "onlyhere.dat" in your main folder, and create a new folder there called "folder". In "folder", also place a "test.dat", and a "onlyinsub.dat".
Then, run this code:
void main() {
var fe;
/*
A ton of tests for file_exists
*/
diag("\n - NORMAL - \n");
fe = file_exists("test.dat");
diag(str_for_num(NULL,fe));
if(file_exists("test.dat")) {
diag(" - exists\n");
} else {
diag(" - does not exist.\n");
}
fe = file_exists("doesnotexist.dat");
diag(str_for_num(NULL,fe));
if(file_exists("doesnotexist.dat")) {
diag(" - exists\n");
} else {
diag(" - does not exist.\n");
}
fe = file_exists("onlyinsub.dat");
diag(str_for_num(NULL,fe));
if(file_exists("onlyinsub.dat")) {
diag(" - exists\n");
} else {
diag(" - does not exist.\n");
}
fe = file_exists("onlyhere.dat");
diag(str_for_num(NULL,fe));
if(file_exists("onlyhere.dat")) {
diag(" - exists\n");
} else {
diag(" - does not exist.\n");
}
diag("\n - SUBFOLDER - \n");
fe = file_exists("folder\\test.dat");
diag(str_for_num(NULL,fe));
if(file_exists("folder\\test.dat")) {
diag(" - exists\n");
} else {
diag(" - does not exist.\n");
}
fe = file_exists("folder\\doesnotexist.dat");
diag(str_for_num(NULL,fe));
if(file_exists("folder\\doesnotexist.dat")) {
diag(" - exists\n");
} else {
diag(" - does not exist.\n");
}
fe = file_exists("folder\\onlyinsub.dat");
diag(str_for_num(NULL,fe));
if(file_exists("folder\\onlyinsub.dat")) {
diag(" - exists\n");
} else {
diag(" - does not exist.\n");
}
fe = file_exists("folder\\onlyhere.dat");
diag(str_for_num(NULL,fe));
if(file_exists("folder\\onlyhere.dat")) {
diag(" - exists\n");
} else {
diag(" - does not exist.\n");
}
diag("\n - COMPARED TO VALUE -\n");
fe = file_exists("test.dat");
diag(str_for_num(NULL,fe));
if(file_exists("test.dat")==1) {
diag(" - exists\n");
} else {
diag(" - does not exist.\n");
}
fe = file_exists("doesnotexist.dat");
diag(str_for_num(NULL,fe));
if(file_exists("doesnotexist.dat")==1) {
diag(" - exists\n");
} else {
diag(" - does not exist.\n");
}
sys_exit("");
}
This is the relevant part of acklog.txt after I run it. Values that seem strange I have commented.
- NORMAL -
1 - exists
0 - does not exist.
0 - does not exist.
1 - exists
- SUBFOLDER -
1 - exists
0 - does not exist.
1 - exists
1 - exists //should be 0 - does not exist!!
- COMPARED TO VALUE -
1 - does not exist. //should be 1 - exists
0 - does not exist.