4D is making your developer’s life easier with two new commands to effortlessly manage file or folder paths. Save valuable time with the Path to object command which, in a single line of code, extracts the extension, the file name or the parent folder. Then you can modify and recombine the different object attributes to compose a new path with Object to path.
Extract path elements
With Path to object, you can easily split paths into several parts, returned as object attributes:
- Parent folder
- Is a folder or not
// Split a path written with system delimiter
$pathSys:=Path to object("C:\\4D\\resources\\images\\4D.jpg")
Note that the command supports both system and POSIX paths. It can also tell if you passed a folder or a file based on the last character of the path input parameter.
You now have a simple way to modify the elements of a path and rebuild it with the Object to path command. Easy!
// Duplicate a document in its own folder:
$o:=Path to object($path)
// Rename document
// Make a copy of the document
COPY DOCUMENT($path;object to path($o))
You can also use the returned object in any 4D command requesting a path:
$o:=Path to object("C:\\4D\\resources\\images\\4D.jpg")
$doc:=Select document($o.name+$o.extension;$o.extension; "Save as";File name entry)
The Path to object and Object to path commands should now be used to replace the calls to the deprecated commands, _o_Document type and _o_SET DOCUMENT TYPE.
Always good to mention, 4D v16 R6 takes full advantage of modern system APIs on macOS for file and folder manipulation. We have run benchmark tests performing various operations such as listing folder contents, checking file properties, reading or copying small files, on folders with thousands of files.
The results show that the execution time is 6 times faster in general and up to 30 times faster when listing the files present at a given location.