Skip to main content

TrFile_ListFolder (function reference)

By June 1, 2024June 4th, 2024Online Help, Troi File Plug-in
Troi File Plug-in > Functions reference > TrFile_ListFolder
Troi File Plug-in for FileMaker Pro

TrFile_ListFolder

Lists what is inside a folder (directory). It will return all files and/or folders, depending on the switches given.

SyntaxFunction badge

TrFile_ListFolder( switches ; folderPath )

Parameters

switches these determine the items that are listed
folderPath the path to the folder to list

Switches

switches can be one or more of the following:

-Files list all files in this folder
-Folders list all folders (subdirectories) in this folder
-Showaliases list all aliases (shortcuts) in this folder
-Showshortcuts list all aliases (shortcuts) in this folder (you can use the one you like)
-Showinvisibles list all invisible files and folders
-Showpointdirs Windows: list also the directory . (current dir) and .. (parent dir)
-Showpointdirs macOS: this switch is ignored
-Longnames (default) macOS: return long names, possibly more than 31 characters
-Shortnames macOS: return shortened names, less than 31 characters long

You can also add these switches:

-Recursive get the list of files and folders and all the subfolders of the folder you are listing
-ShowPackageContents (macOS) also list the contents of a package folder (used in combination with -Recursive)
-DontEncodeSlash (macOS) don’t encode slashes in name with %2F (in combination with -Recursive)
-ReturnAtEnd add an extra return character after the last found item in the list
-AddFolderSuffix this will add a trailing slash to folders in the result, making them recognizable as folders

Returned Result

Data type returned

Text

Result

folder list a list of names of the items separated by returns.

Originated in

Troi File Plug-in 1.2

Compatibility

FileMaker Pro 17 to FileMaker Pro 21 (2024)

Considerations

You can recursively get the list of files and folders and all the subfolders of the folder you are listing. To enable this add the switch “-Recursive”. Note that files and folders in subfolders will be listed with the relative folderpath, with a slash as separator, for example “SubFolder1/filename.txt”.
Starting with v5.5 the switch “-Longnames” is the default, so you no longer need to specify it. If you want short names (on macOS): use the “-Shortnames” switch. Mac OS 9.x supported only names up to 31 characters, so with the “-Shortnames” switch the names will be shorter or equal than 31 characters, for longer names the file name will look like mygreatimagefilebuttoo#E11E.txt

You can use FileMaker styled paths, like “filewin:/C:/MyFiles/”.

Example

Set Field [ result ; TrFile_ListFolder ( "-Files -Folders " ; "Mac HD:" ) ]

This will return a list of all files and folders on the hard disk “Mac HD”. Note that the order of the switches is not relevant. This might be returned:

Test.fmp12¶
Desktop Folder¶
Program files¶
etc…

On Windows an example usage is:

Set Field [ result ; TrFile_ListFolder ( "-Files -Showshortcuts" ; "C:\Data\" ) ]

This will return a list of all files and shortcuts on the hard disk “C:\Data\”.

Example 2

We assume that in your FileMaker file the following fields are defined:

  gFolderPath		Global, text
  gFolderList		Global, text

gFolderPath should contain the path to the folder, for example “D:\Logs\Data\” (Windows) or “Mac HD:Logs:Data:” (Mac OS). In a script add the following scriptstep:

Set Field [ gFolderList ; TrFile_ListFolder ( "-Files -Folders " ; gFolderPath ) ]

This will list the contents of the folder specified in the gFolderPath.

Used in example file

ListFolder.fmp12

Related functionsFunction badge

TrFile_GetFolderSize
TrFile_SaveFileDialog
TrFile_SelectFolderDialog
TrFile_SetDefaultFileSpec

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 17 to 2024 –> TrFile_ListFolder (filep4254) 2024-0604 19:25:23