Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

Files.List

Queries list of file names in folder.

Component Version macOS Windows Linux Server iOS SDK
Files 2.8 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "Files.List"; Path { ; filter; ExtensionFilter } )   More

Parameters

Parameter Description Example Flags
Path Native path to the directory. "C:\Test"
filter Optional, limits what is returned.
Default is 0 to report all files.
Pass a combination of 1 for showing only files, 2 for showing only directories and 4 for showing only visible items.
Add 8 if the path includes the file name specification with wildcards; a.k.a glob.
Combined pass 4+1 for visible files or 2+1 for visible directories.
5 Optional
ExtensionFilter Optional, a filter for getting only files with matching file extension. ".txt" Optional

Result

Returns list of files separated by return.

Description

Queries list of file names in folder.
The list of names is separated by new line character.
This function needs a native path. Please use Path.FileMakerPathToNativePath function in order to convert a FileMaker style path to a native path.
With filter parameter being 8 on Windows, you can pass a path with wildcards directly and ExtensionFilter parameter is ignored. This is not supported on macOS.

See also Files.ListRecursive. You can filter result with List.MatchesPostfix to get list with one file extension only.

Our plugin does not sort and return the files in the order the OS returned them. If you need sorting, please check List.Sort function. Also use List.RemovePrefix or List.RemovePostfix to filter list further.

On macOS, if you can't read a directory, please also check privacy system settings for whether FileMaker has permissions to look into desktop, documents or downloads folder or remote volumes.

Examples

Queries files in Users folder on Mac:

Set Variables [ $FileList; Value: MBS("Files.List"; "/Users") ]

Queries visible files in windows folder:

Set Variables [ $FileList; Value: MBS("Files.List"; "c:\\Windows\\"; 5) ]

Queries DLL files in windows folder:

Set Variables [ $FileList; Value: MBS("Files.List"; "c:\\Windows\\"; 0; ".dll") ]

Queries Applications with name starting with e in windows folder:

Set Variables [ $FileList; Value: MBS("Files.List"; "c:\\Windows\\e*.exe"; 8) ]

Find FileMaker databases in a folder:

Set Variables [ $FileList; Value: MBS("Files.List"; "c:\\Users\\Christian\\Desktop"; 0; ".fmp12”)]

Query all file names and sizes for files on desktop:

While(
[
    names = "";
    // query list of visible files on desktop
    folder = MBS("Folders.UserDesktop");
    list = MBS( "Files.List"; folder; 1+4 );
    count = ValueCount(list);
    index = 1
] ;
    index ≤ count ;
[
    filename = GetValue(list; index);
    filepath = MBS("Path.AddPathComponent"; folder; filename);
    // query size for each file
    size = MBS( "Files.FileSize"; filepath);
    names = names & filename & " -> " & size & ¶;
    index = index + 1
] ;
// return all the names
names )

Example result:
test.zip -> 834
test.rtf -> 400

Import all files in a folder:

# list files in a folder
Set Variable [ $r ; Value: MBS("Files.List"; $FolderPath) ]

# loop over the files
Set Variable [ $count ; Value: ValueCount ( $r ) ]
Set Variable [ $index ; Value: 0 ]
If [ $count>0 ]
    Loop
        # build path
        Set Variable [$fileName; GetValue ( $r ; $index+1 )]
        Set Variable [$filePath; Value: MBS( "Path.AddPathComponent"; $FolderPath; $fileName )]
            Set Variable [$fileData; Value: MBS("Container.ReadFile"; $filePath)]

        # create record for new file
        New Record/Request
            Set Field [MyData::Container; $fileData ]
        Set Field [MyData::Name; $fileName ]
        Commit Records/Requests [ With dialog: Off ]

        Set Variable [ $index ; Value: $index + 1 ]
        Exit Loop If [ $index = $count ]
    End Loop
End If

See also

Release notes

  • Version 13.5
    • Added IsApplication and IsPackage for Files.ListAsJSON function.
    • Fixed Files.ListAsJSON function to not filter invisible files on macOS without asked to do that.
  • Version 12.2
    • Fixed Files.List to better check directory status on macOS using alternative code path.
  • Version 11.5
    • Fixed Files.ListAsJSON to query date and size of a symlink instead of the target.
  • Version 10.5
  • Version 8.4
  • Version 7.3
    • Added new flag for Files.ListRecursive to ignore invisible folders and better check for hidden elements.
  • Version 7.1

Example Databases

Blog Entries

This function checks for a license.

Created 18th August 2014, last changed 2nd August 2023


Files.LaunchFile - Files.ListAsJSON