Create File/Dir
Creates a file or directory in a specified path
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
if ContinueOnError property is true, no error is caught when the project is executed even if Catch node is used.
Input
- Path - The path of the file/directory that will be created.
Output
- Path - The path of the file/directory that is created.
Options
- Type - To determine whether file or directory will be created.
- File - Creates file to the given path.
- Directory - Creates directory to the given path.
How It Works
The Create File/Dir node creates new files or directories through the following process:
- Validates that the path is not empty
- Verifies that a file type (File or Directory) has been selected
- Checks if the file or directory already exists at the specified path
- For directories: Creates all necessary parent directories using MkdirAll (permissions: 0755)
- For files: Creates an empty file (permissions: 0644)
- Returns the created path in the output variable
Requirements
- Valid path for the file or directory to be created
- Type selection (File or Directory) must be specified
- Write permissions in the parent directory
- Parent directories in the path will be automatically created for directories
- The specified path must not already exist (files and directories cannot be overwritten)
Error Handling
| Error Code | Description |
|---|---|
FileSystem.Create.ErrOnCreate | Node configuration parsing failed |
Core.CSV.AppenCSV.OnMessage | Input message parsing failed (legacy error code) |
Core.FileSystem.Create.ErrPath | Path is empty |
Core.FileSystem.Create.ErrFileType | File type must be selected (File or Directory) |
Core.FileSystem.Create.ErrExists | File or directory already exists at the specified path |
Core.FileSystem.Create.ErrMkdirAll | Failed to create directory (permission denied or invalid path) |
Core.FileSystem.Create.ErrCreate | Failed to create file (permission denied or invalid path) |
Usage Examples
Example 1: Create a New File
Create an empty log file for an automation process:
{
"path": "C:\\Logs\\automation_log.txt"
}
Configuration:
- Type: File
Example 2: Create a Directory Structure
Create a new directory for storing reports:
{
"path": "D:\\Reports\\2024\\January"
}
Configuration:
- Type: Directory
This creates all parent directories (Reports, 2024) if they don't exist.
Example 3: Dynamic File Creation
Create a file with a dynamic name using variables:
{
"path": "C:\\Output\\report_{{ $date }}_{{ $time }}.csv"
}
Configuration:
- Type: File
The output path variable can be used in subsequent nodes.
Usage Notes
- Files are created as empty files (0 bytes) with read/write permissions (0644)
- Directories are created with execute permissions (0755) allowing file creation inside them
- For directories, all parent directories in the path are automatically created if they don't exist
- For files, parent directories must already exist or the operation will fail
- The node will fail if a file or directory already exists at the specified path
- Created path is returned in the output variable for use in subsequent nodes
- Both absolute and relative paths are supported
Tips
- Use Path Exists node before Create File/Dir to check if the path already exists
- For file creation, ensure parent directories exist or create them first
- Directory creation is more forgiving as it creates all parent directories automatically
- Use dynamic paths with variables to create unique files/directories for each execution
- Consider using timestamped paths for logs and reports to avoid conflicts
- Combine with Delete File/Dir node to implement file rotation strategies
- Use Continue On Error when creating directories that might already exist
Related Nodes
- Path Exists - Check if file/directory exists before creation
- Delete File/Dir - Remove files or directories
- Write File - Write content to the created file
- List Directory - List contents of the created directory