Using path elements in objects

Automatically translated from English

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
  • Name
  • Extension
  • 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.

Build path

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.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.

Performance improvement

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.

Fabrice Mainguené

• Product Owner •

Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.

After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.