Skip to main content

TrFile_Search (function reference)

Troi File Plug-in for FileMaker Pro

TrFile_Search

Search a folder (or volume) for a file or folder (directory).

SyntaxFunction badge

TrFile_Search ( switches ; folderPath ; searchName )

Parameters

switches these determine the items that are listed
folderPath the path to the folder (or volume) in which to search
searchName the (part of the) filename or foldername you want to find

Switches

switches can be one or more of the following:

-Files search for files
-Folders search for folders
-Exactname the filename must exactly match the searchname
-Showaliases search also aliases (shortcuts)
-Showshortcuts search also aliases (shortcuts) (you can use the one you like)
-Showinvisibles search also invisible files and folders
-Shortnames return shortened names, less than 31 characters long (for classic macOS)
-ReturnAtEnd add an extra return character after the last found item in the list
-Exhaustive search by enumerating the folders, might be slow for folders with lots of items
-UseSpotlight (macOS only) search for files and folders using Spotlight
-FileMakerPathFormat return the result as fully qualified FileMaker formatted paths

Returned Result

Data type returned

Text

Result

a list of paths of the found items separated by returns.

Originated in

Troi File Plug-in 1.2

Compatibility

FileMaker Pro 16 to FileMaker Pro 2023

Considerations

You can also specify a folder in which the search must be done, instead of searching the whole volume.
Note that the final path is also followed by a return!

You can search using Spotlight on macOS by adding the switch -useSpotlight. But note that Spotlight does not return all files, for example it omits hidden (invisible) files. Also Spotlight search will not work if a disk is not indexed yet. It is however quite fast.

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, longer filenames will look like mygreatimagefilebuttoo#E11E.txt

Example

Set Field [ result ; TrFile_Search ( "-files -folders" ; "HD:Users:Kes:" ; "readme" ) ]

This will return a list of all files and folders in folder “HD:Users:Kes:” with the name ‘readme’. Note that the order of the switches is not relevant. This might be returned:

HD:Users:Kes:Foto, film, geluid:Geluiden:Alert!!!:Readme¶
HD:Users:Kes:Programma’s:Beeld:GIFConverter 2.3.7 ƒ:README-registration¶
HD:Users:Kes:Programma’s:Beeld:MOVIES:OBJTOOL:README, Make QTVR Object¶
etc…

On Windows an example use is:

Set Field [ result ; TrFile_Search ( "-files -folders" ; "C:" ; "readme" ) ]

Example 2

Set Variable [ $result ; TrFile_Search ( "-files -folders -invisibles" ; "HardDisk:" ; "readme" ) ]

This will return a list of all files and folders on the hard disk “HardDisk” with the name ‘readme’, including invisible files.

Example 3

Set Variable [ $result ; TrFile_Search ( "-files -FileMakerPathFormat" ; "HardDisk:" ; "readme" ) ]

This will return a list of all files on the disk “HardDisk” with the name ‘readme’, The result will be a list of fully qualified FileMaker style formatted path, for example:

/HardDisk/Users/ad/kip/readme.txt
/HardDisk/Users/ad/mus/data/grreadmees.doc

Used in example file

DataIn.fmp12

Related topics

Troi File Plug-in online help (overview)


Online Help Page for Troi File Plug-in for 16 to 2023 –> TrFile_Search (filep4270) 2023-0601 15:57:03