4D Blog

Home Product Object notation to handle files and folders

Object notation to handle files and folders

May 2, 2019

Product

4D already provides commands to handle files and folders, but what about new commands that take advantage of the power of object notation?

Objects have changed the way many 4D developers write code, making it more generic, flexible, easier, and faster. Now this wave of change is extended to files and folders. In this blog post, we’ll show you how easy it is to manipulate an object in order to retrieve the attributes of a file or folder (rather than calling several commands and storing the information in multiple variables). Things are getting a lot easier!

Database example

Handling folders

New 4D commands

A new Folder command has been added which lets you create a folder object from a constant, a POSIX path, or a platform path.

myFolder:=Folder(fk desktop folder)
myFolder:=Folder("/RESOURCES/Images")
myFolder:=Folder("c:\\Archives\\";Platform path)

New Folder object

The folder object provides properties and methods so you can create and manipulate folders.

Here’s a few examples of folder properties:

// Name
$name:=myFolder.name
// Modification date
$date:=myFolder.modificationDate
// Modification time
$time:=myFolder.modificationTime

And there’s methods available, too! You can create(), moveTo(), rename(), delete(), etc.

// Move to
myMoveTo:=myFolder.moveTo(destinationFolder)
// Rename
myRename:=myFolder.rename("NewName")
// Delete
myFolder.delete(Delete with contents)
// List of files in myFolder
colFiles:=myFolder.files()

Folder objects contain references to folders that may or may not already exist on disk. For example, when you execute the Folder method to create a new folder, a valid folder object is created but nothing is actually stored on disk until you call the create() method.

newFolder=Folder(fk documents folder).folder("Archives/2019")
$result:=newFolder.exists // return False

newFolder:=newFolder.create()
$result:=newFolder.exists // return True

Handling files

New 4D commands

We’ve also added a File command to create a file object from a constant, a POSIX path, or a platform path.

myFile:=File(User settings file)
myFile:=File("/RESOURCES/Images/picture.png")
myFile:=File(Structure file;fk platform path)

New file object

As with folders, the new file object lets you access the file attributes and manipulate files.

// Name
$name:=myFile.name
// Extension
$extension:=myFile.extension
// Creation date
$date:=myFile.creationDate
// Creation time
$time:=myFile.creationTime

Also like folders, files have methods, too.  You can write and read the contents of a file, move it, delete it ,and so on.

// Create a file with
myFile.setText($text)
// Retrieve the content of the file
$text:=myFile.getText()
// Delete
myFile.delete()

For the full list of attributes and methods, check out the doc center.

Discuss

Tags Files and Folders, Objects, Programming, v17 R5, v18

Latest related posts

  • October 23, 2025

    Starting Qodly studio is just two clicks away

  • October 22, 2025

    Localize your Qodly Pages: A Practical Guide

  • October 21, 2025

    New Way to Control Your HTTP Responses

Vanessa Talbot
Vanessa Talbot
• Product Owner •Vanessa Talbot joined 4D Program team in June, 2014. As a Product Owner, she is in charge of writing the user stories then translating it to functional specifications. Her role is also to make sure that the feature implementation delivered is meeting the customer need.Since her arrival, she has worked to define key features in 4D. She has worked on most of preemptive multi-threading new features and also on a very complex subject: the new architecture for engined application. Vanessa has a degree from Telecom Saint-Etienne. She began her career at the Criminal Research Institute as a developer for the audiovisual department. She has also worked in media and medical fields as expert in technical support, production as well as documenting new features.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application Class Client/Server Code editor Collections Compatibility settings Formula Google Listbox Logs Mail Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy