# get_file_type

Definition: | integer res = get_file_type(string filename)
Description: | Get the type of a file or directory. filename: the name of the file to query. It must not have wildcards (? and *). Returns an integer: FILETYPE_UNDEFINED (-1) if file could be multiply defined FILETYPE_NOT_FOUND (0) if filename does not exist FILETYPE_FILE (1) if filename is a file FILETYPE_DIRECTORY (2) if filename is a directory
pwa/p2js: | Not supported.
Comments: | Both forwardslash ('/') and backslash ('\\') are handled for all platforms. A trailing slash is optional on directories, it makes no difference whether one is present or not. The four return values above are automatically declared in psym.e/syminit(). Note this routine can be pretty slow, especially for directories, and you should certainly avoid re-checking the same thing over and over again whenever possible. The original version of demo\rosetta\Count_examples.exw was ten times slower than it is now simply because it (re-)checked the existence of the rc_cache directory in open_download() rather than just once at the start, and that is not a good plan when you’re going to do it 1,440+ times.
Example: |
    if get_file_type("C:/Program Files (x86)/Phix/builtins/vm/papnd.e")!=FILETYPE_FILE then ?9/0 end if
    if get_file_type("C:/Program Files (x86)/Phix/builtins/vm")!=FILETYPE_DIRECTORY then ?9/0 end if
    if get_file_type(`C:\Program Files (x86)\Phix\builtins\vm\`)!=FILETYPE_DIRECTORY then ?9/0 end if
Implementation: | See builtins\pfile.e (an autoinclude) for details of the actual implementation.
See Also: | dir
Technicalia | For compatibility with Euphoria, file_type() is a simple alias of get_file_type(), and behaves identically.