Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
Files.ListAsJSON
Queries list of file names in folder as JSON.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
Files | 10.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example | Flags |
---|---|---|---|
Path | Native path to the directory. | "C:\Test" | |
Keys | The keys to retrieve. Pass a list of values including Size, CreationTimeStamp, AccessTimeStamp, ModificationTimeStamp, Visible. Name, Directory and Type can be passed, but are always included. If keys is "All", we include all keys. Added IsApplication and IsPackage values for v13.5. |
Optional | |
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. 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 JSON array or error.
Description
Queries list of file names in folder as JSON.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.
TimeStamps are returned in the FileMaker formatting. On Windows a key AlternateFileName may be included in result if the file has an alternative file name for DOS.
If you need sorting, please check JSON.SortWithEvaluate function.
We can add more Keys if needed. Let us know if you need another value for all files.
Examples
List files on desktop:
MBS( "Files.ListAsJSON"; MBS("Folders.UserDesktop"); "Size¶CreationTimeStamp¶AccessTimeStamp¶ModificationTimeStamp¶Visible" )
Example result:
[
{
"Name": "Projects",
"Directory": true,
"Type": "Directory",
"Visible": true,
"Size": 64,
"CreationTimeStamp": "28.09.2020 15:52",
"AccessTimeStamp": "28.09.2020 15:51:58",
"ModificationTimeStamp": "28.09.2020 15:51:58"
}
]
List files and sort by name:
MBS( "JSON.SortWithEvaluate";
MBS( "Files.ListAsJSON";
MBS("Folders.UserDesktop");
"Size" );
"JSONGetElement ( leftJSON; \"Name\") < JSONGetElement ( rightJSON; \"Name\")" )
List files and sort by size descending:
MBS( "JSON.SortWithEvaluate";
MBS( "Files.ListAsJSON";
MBS("Folders.UserDesktop");
"Size" );
"JSONGetElement ( leftJSON; \"Size\") > JSONGetElement ( rightJSON; \"Size\")" )
List files and sort by modification time stamp:
Let ( [
path = MBS("Folders.UserDesktop");
list = MBS( "Files.ListAsJSON"; path; "CreationTimeStamp¶ModificationTimeStamp" );
sort = MBS( "JSON.SortWithEvaluate"; list; "GetAsTimeStamp(JSONGetElement ( leftJSON; \"ModificationTimeStamp\")) < GetAsTimeStamp(JSONGetElement ( rightJSON; \"ModificationTimeStamp\"))" )
];sort)
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 11.5
- Fixed Files.ListAsJSON to query date and size of a symlink instead of the target.
- Version 10.5
- Added Files.ListAsJSON function to list files and return it as JSON.
Blog Entries
- MBS Plugin Advent calendar: 12 - Files
- MBS FileMaker Plugin, version 13.5pr7
- MBS FileMaker Plugin, version 13.5pr6
- MBS FileMaker Plugin, version 11.5pr7
- New in MBS FileMaker Plugin 10.5
- Neues MBS FileMaker Plugin 10.5 - Über 6400 Funktionen in einem Plugin
- MBS FileMaker Plugin 10.5 - More than 6400 Functions In One Plugin
- MBS FileMaker Plugin, version 10.5pr1
- Embrace JSON
FileMaker Magazin
This function checks for a license.
Created 28th September 2020, last changed 30th October 2023