The native macOS file systems impose remarkably few restrictions on file names and path lengths. Mac users can name files with long names and descriptive names. Useful as these are, such file names can prove a burden when files need to be shared, copied to other file systems, or uploaded to certain cloud services.
Indeed many other systems limit the length of file names. Before attempting to move files to such systems it is useful to check names for compliance with restrictions. Hence the need to search file files with names longer than the imposed limit.
In this post, we are going to check a folder structure for files with names more than 140 characters long.
HoudahSpot builds upon the macOS Spotlight file index. This does not allow for searches by file name length. Still, you can use HoudahSpot to find files with long names.
In HoudahSpot you can pare down search results using two distinct techniques: combine search criteria or apply filters to existing search results. This second approach is commonly used to segment search results and explore these in manageable chunks.
Filters in HoudahSpot can narrow down file lists in ways that are not possible using search criteria. HoudahSpot can, for example, filter results by folder name. Filters by file name, path, or parent folder name can also use regular expressions.
Regular expressions are used to match names against a pattern. In its most basic form, a regular expression can filter files to show only those having a name that starts with a given prefix. Patterns can also – with skill and effort – be configured to express complex rules.
Let’s use a regular expression to match file names that are 140 characters or longer.
First, we need HoudahSpot to list all files in the folder structure we want to check for long file names. We start by setting the Locations list in a HoudahSpot search to point at the folder where our files are located.
Next, we need to coax HoudahSpot into listing all files found within that folder and all nested folders. HoudahSpot uses the asterisk as a wildcard: it matches any number of letters. Thus a search for “Name contains *” will find all files with the targeted locations.
Start the search. HoudahSpot will list all files in our selected folder. This is the list of files we want to check for overly long file names.
In HoudahSpot 6, the filter options are found by clicking the filter button in the header above search results. The pop-over window lists all currently active filters. The list currently has one filter. It is not active since we have not yet provided a value or pattern.
We want to filter by file name. Select that option from the first pop-up menu.
In the second pop-up menu, select the option to use a regular expression. We can then chose to see files that match or do not match the pattern we will provide. We want the files to match our pattern.
Next, type in the following regular expression:
The period symbol in the regular expression matches any character. We want to match files that have a minimum of 140 characters and don’t specify an upper limit.
Once you have set up the filter, HoudahSpot will only list matching files. The header at the top of the results pane will show how many files were found and how are shown after applying filters. The filter button is highlighted as long as a filter is applied.