fl >= 0 checking for new_flist( path, mask ) doesn't seem to return -1 when an invalid path is given

Pixilang programming language
Post Reply
User avatar
Logickin λ
Posts: 169
Joined: Sat Sep 08, 2018 8:31 pm
Contact:

fl >= 0 checking for new_flist( path, mask ) doesn't seem to return -1 when an invalid path is given

Post by Logickin λ »

After messing around about the switch case work around, I am now working on some kind of validation for checking valid file path.
I looked at the fild_list.pixi example and try to play around it with different folder path.

The default example uses CURRENT_PATH, and it works as expected, showing every single file names in the folder;
however, I tried to insert an invalid path that is clearly not exists (FOOBARNOTEYYEP:/clearly not existed/56pb0934e790567wq0349vg756w):

Code: Select all

include "../show_log.pixi"

path = "FOOBARNOTEYYEP:/clearly not existed/56pb0934e790567wq0349vg756w"
mask = -1 //Examples: "txt/doc", "avi"; or -1 for all files.
fl = new_flist( path, mask )
if fl >= 0
{
    logf( "Some files found in %s\n", path )
    while( 1 )
    {
	file_name = get_flist_name( fl )
	file_type = get_flist_type( fl ) //0 - file; 1 - directory;
	if file_type == 0
	{
	    logf( "FILE %s%s\n", path, file_name )
	}
	else
	{
	    logf( "DIR  %s%s\n", path, file_name )
	}
	if flist_next( fl ) == 0 //Go to the next file
	{
	    //No more files
	    break
	}
    }
    remove_flist( fl )
}

show_log()
I thought the function will return -1 when I inserted a clearly wrong path, but the "Some files found in %s\n" message was still logged into the console.
Am I misunderstood how this function work? If this function cannot return -1 for invalid file path, is there any functions can let me check the invalid file path without attempt to open a file? (as the file name is not a constant)
Post Reply