Files and Folders Manipulation
Introduction
In the polyglot backend code of the Netuno platform, we can manipulate any file or folder.
Manipulation consists of being able to create, rename, and delete files and folders, change the contents of files, and list the contents of folders. In general, these are the operations we typically need to perform programmatically.
The Netuno platform has low-code programming features that allow you to manipulate the application's internal folders and files, but also any files and folders in the system in general, that is, outside the application.
This is useful when we need to automate a process that requires manipulating any file; let's see how.
The low-code polyglot programming features that allow you to manipulate files are:
_app- Application_storage- Storage_os- Operating System
Through these resources we have the methods to:
.file- Existing file..folder- Existing folder..path- A generic path can be either a file or a folder, and it may or may not exist.
With these methods we obtain an object of type File, which provides all the means for manipulating files, folders and paths in general, allowing operations such as:
- Create files and folders.
- Delete files and folders.
- List the contents of folders.
- Rename files and folders.
- Read and write data to files.
- Delete folders and their respective subfolders and files recursively.
Application
To perform the main file and folder manipulation operations within the application structure, we use
the _app resource:
Folders in the Application
Ensures that an existing folder is retrieved, for example:
- JavaScript
- Python
- Ruby
- Kotlin
- Groovy
const myFolder = _app.folder("my/folder")
const myFolder = _app.folder("my/folder")
const myFolder = _app.folder("my/folder")
const myFolder = _app.folder("my/folder")
const myFolder = _app.folder("my/folder")
Files in the Application
Ensures that a file that exists is retrieved, for example:
- JavaScript
- Python
- Ruby
- Kotlin
- Groovy
const myFile = _app.file("my/folder/file.txt")
const myFile = _app.file("my/folder/file.txt")
const myFile = _app.file("my/folder/file.txt")
const myFile = _app.file("my/folder/file.txt")
const myFile = _app.file("my/folder/file.txt")
Paths in the Application
Retrieve a file or folder path, regardless of whether it exists or not, for example:
- JavaScript
- Python
- Ruby
- Kotlin
- Groovy
const newFile = _app.path("my/folder/new-file.txt")
const newFile = _app.path("my/folder/new-file.txt")
const newFile = _app.path("my/folder/new-file.txt")
const newFile = _app.path("my/folder/new-file.txt")
const newFile = _app.path("my/folder/new-file.txt")
Storage
To perform the main file and folder manipulation operations within the application's 📁 storage folder,
we use the _storage resource:
Folders in Storage
Ensures that a folder that exists is retrieved, for example:
- JavaScript
- Python
- Ruby
- Kotlin
- Groovy
// The actual path to the folder will be:
// storage/filesystem/server/my/folder
const storageMyFolder = _storage.filesystem("server", "my/folder")
const myFolder = storageMyFolder.folder()
// The actual path to the folder will be:
# storage/filesystem/server/my/folder
storageMyFolder = _storage.filesystem("server", "my/folder")
myFolder = storageMyFolder.folder()
// The actual path to the folder will be:
# storage/filesystem/server/my/folder
storageMyFolder = _storage.filesystem("server", "my/folder")
myFolder = storageMyFolder.folder()
// The actual path to the folder will be:
// storage/filesystem/server/my/folder
val storageMyFolder = _storage.filesystem("server", "my/folder")
val myFolder = storageMyFolder.folder()
// The actual path to the folder will be:
// storage/filesystem/server/my/folder
final storageMyFolder = _storage.filesystem("server", "my/folder")
final myFolder = storageMyFolder.folder()
Files in Storage
Ensures that a file that exists is retrieved, for example:
- JavaScript
- Python
- Ruby
- Kotlin
- Groovy
// The actual file path will be:
// storage/filesystem/server/my/folder/file.txt
const storageFile = _storage.filesystem("server", "my/folder", "file.txt")
const file = storageArquivo.file()
// The actual file path will be:
# storage/filesystem/server/my/folder/file.txt
storageFile = _storage.filesystem("server", "my/folder", "file.txt")
file = storageArquivo.file()
// The actual file path will be:
# storage/filesystem/server/my/folder/file.txt
storageFile = _storage.filesystem("server", "my/folder", "file.txt")
file = storageArquivo.file()
// The actual file path will be:
// storage/filesystem/server/my/folder/file.txt
val storageFile = _storage.filesystem("server", "my/folder", "file.txt")
val file = storageArquivo.file()
// The actual file path will be:
// storage/filesystem/server/my/folder/file.txt
final storageFile = _storage.filesystem("server", "my/folder", "file.txt")
final file = storageArquivo.file()
Paths in Storage
Retrieve a file or folder path, regardless of whether it exists or not, for example:
- JavaScript
- Python
- Ruby
- Kotlin
- Groovy
// The actual new folder path will be:
// storage/filesystem/server/my/new-folder
const storageFolder = _storage.filesystem("server", "my/new-folder")
const folder = storageFolder.path()
// The actual new file path will be:
// storage/filesystem/server/my/folder/new-file.txt
const storageFile = _storage.filesystem("server", "my/folder", "new-file.txt")
const file = storageFile.path()
// The actual new folder path will be:
# storage/filesystem/server/my/new-folder
storageFolder = _storage.filesystem("server", "my/new-folder")
folder = storageFolder.path()
# The actual new file path will be:
# storage/filesystem/server/my/folder/new-file.txt
storageFile = _storage.filesystem("server", "my/folder", "new-file.txt")
file = storageFile.path()
// The actual new folder path will be:
# storage/filesystem/server/my/new-folder
storageFolder = _storage.filesystem("server", "my/new-folder")
folder = storageFolder.path()
# The actual new file path will be:
# storage/filesystem/server/my/folder/new-file.txt
storageFile = _storage.filesystem("server", "my/folder", "new-file.txt")
file = storageFile.path()
// The actual new folder path will be:
// storage/filesystem/server/my/new-folder
val storageFolder = _storage.filesystem("server", "my/new-folder")
val folder = storageFolder.path()
// The actual new file path will be:
// storage/filesystem/server/my/folder/new-file.txt
val storageFile = _storage.filesystem("server", "my/folder", "new-file.txt")
val file = storageFile.path()
// The actual new folder path will be:
// storage/filesystem/server/my/new-folder
final storageFolder = _storage.filesystem("server", "my/new-folder")
final folder = storageFolder.path()
// The actual new file path will be:
// storage/filesystem/server/my/folder/new-file.txt
final storageFile = _storage.filesystem("server", "my/folder", "new-file.txt")
final file = storageFile.path()
Operating System
To perform the main file and folder manipulation operations anywhere in the operating system, we use
the _os feature:
Folders in the Operating System
Ensures that a folder that exists is retrieved, for example:
- JavaScript
- Python
- Ruby
- Kotlin
- Groovy
const myFolder = _os.folder("/tmp/my/folder")
const myFolder = _os.folder("/tmp/my/folder")
const myFolder = _os.folder("/tmp/my/folder")
const myFolder = _os.folder("/tmp/my/folder")
const myFolder = _os.folder("/tmp/my/folder")
Files in the Operating System
Ensures that a file that exists is retrieved, for example:
- JavaScript
- Python
- Ruby
- Kotlin
- Groovy
const myFile = _os.file("/tmp/my/folder/file.txt")
const myFile = _os.file("/tmp/my/folder/file.txt")
const myFile = _os.file("/tmp/my/folder/file.txt")
const myFile = _os.file("/tmp/my/folder/file.txt")
const myFile = _os.file("/tmp/my/folder/file.txt")
Paths in the Operating System
Retrieve a file or folder path, regardless of whether it exists or not, for example:
- JavaScript
- Python
- Ruby
- Kotlin
- Groovy
const newFile = _os.path("/tmp/my/folder/new-file.txt")
const newFile = _os.path("/tmp/my/folder/new-file.txt")
const newFile = _os.path("/tmp/my/folder/new-file.txt")
const newFile = _os.path("/tmp/my/folder/new-file.txt")
const newFile = _os.path("/tmp/my/folder/new-file.txt")