TrFile_ListFolder (function reference)

By May 1, 2017 May 22nd, 2019 Online 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

switchesthese determine the items that are listed
folderPaththe path to the folder to list

Switches

switches can be one or more of the following:

-Fileslist all files in this folder
-Folderslist all folders (subdirectories) in this folder
-Showaliaseslist all aliases (shortcuts) in this folder
-Showshortcutslist all aliases (shortcuts) in this folder (you can use the one you like)
-Showinvisibleslist all invisible files and folders
-ShowpointdirsWindows: list also the directory . (current dir) and .. (parent dir)
-ShowpointdirsMac OS: this switch is ignored
-Longnames(default) Mac OS: return long names, possibly more than 31 characters
-ShortnamesMac OS: return shortened names, less than 31 characters long

You can also add these switches:

-Recursiveget the list of files and folders and all the subfolders of the folder you are listing
-ShowPackageContents(Mac OS) also list the contents of a package folder (used in combination with -Recursive)
-DontEncodeSlash(Mac OS) don’t encode slashes in name with %2F (in combination with -Recursive)
-ReturnAtEndadd an extra return character after the last found item in the list
-AddFolderSuffixthis 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 14 to 18

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 Mac OS X): 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.

Related functionsFunction badge

TrFile_SaveFileDialog
TrFile_SelectFolderDialog
TrFile_SetDefaultFileSpec

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 14 to 18 –> TrFile_ListFolder (filep4254) 2019-0522 17:06:14