KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Folder .delete() Function and Hidden .DS_Store Files
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac
Published On: January 30, 2023

When handling files and folders, you may come across the following scenario. You use the Folder object’s .delete() function, along with the “Delete only if empty'' constant, to delete empty folders on the machine’s disk. When running this on a Mac machine, however, an error pops up, saying the folder is not actually empty; when checking the folder causing the error, you see that the folder visibly does not contain any files.

This is because the folder may still have a hidden .DS_Store file, even after deleting all of its contents. The .DS_Store file is a special file specific to Mac that saves metadata and view preferences for the folder it resides inside of. On Windows, this file is treated as any other and is visible in the file explorer by default.

To bypass this, you may use the following utility method to delete the file using the Mac terminal:

#DECLARE($path_t : Text)

If (Is macOS) & (Test path name($path_t)=Is a folder)
   SET ENVIRONMENT VARIABLE("_4D_OPTION_CURRENT_DIRECTORY"; $path_t)
   LAUNCH EXTERNAL PROCESS("find . -name '.DS_Store' -type f -delete")
End if


The Folder .delete() function with “Delete with contents” constant may also be used but must be exercised with caution—as the action is permanent and cannot be reversed.