file_find_first

This function will return the name of the first file that satisfies the mask and the attributes. If no such file exists, then an empty string is returned. The mask can contain a path and can contain wildchars, for example 'C:\temp\*.doc'. The attributes give the additional files you want to see, so the normal files are always returned when they satisfy the mask. You can add up the following constants to see the type of files you want (if you do not wish to add any attributes, use 0):

 

Constant Description
fa_readonly Read-only files
fa_hidden Hidden files
fa_sysfile System files
fa_volumeid Volume-id files
fa_directory Directories
fa_archive Archived files

 

WARNING! This function may not work as you expect due to GameMaker Studio 2 being sandboxed! Please see the section on the File System for more information.

NOTE: This function will not work at all on the HTML5 target, and the filter flags will only work on Windows (use 0 for all other platforms).

 

Syntax:

file_find_first(mask, attr);

Argument Description
mask The mask to use for searching.
attr The specific file attribute to look for.

 

Returns:

String

 

Example:

if directory_exists("\User Content")
    {
    file = file_find_first("/User Content/*.doc", fa_readonly);
    }

This will check to see if the specified directory exists then, if it does, go there and return the first "read only" doc file found.