CreateDirectory Activity
Purpose: This activity creates a directory and all subdirectories if they don't exist. If the directory already exists, the operation succeeds without error. This is useful for ensuring that a directory structure exists before performing file operations.
Input Properties
The directory path to create. This can be a single directory or a nested path (e.g., "C:\Data\SubFolder\Nested").
Type: string
Required: Yes
Example: "C:\Data\NewFolder" or "C:\Data\SubFolder\Nested"
Output Properties
True if the directory was created successfully or already exists, false otherwise.
Type: bool
Note: Returns true if the directory was created or already exists, false if the DirectoryPath is null or empty, if access is denied, or if an error occurs.
The full path of the created directory. If an error occurs, this will contain an error message.
Type: string
Note: Returns the full normalized path of the created directory if successful, or an error message (starting with "Error: ") if the operation fails.
Usage Example
Scenario: Create a single directory Configuration: - DirectoryPath: "C:\Data\NewFolder" Result: - Success: true - CreatedPath: "C:\Data\NewFolder" Scenario: Create nested directories Configuration: - DirectoryPath: "C:\Data\SubFolder\Nested\Deep" Result: - Success: true - CreatedPath: "C:\Data\SubFolder\Nested\Deep" (all parent directories created automatically)
Error Handling
Important: The activity handles errors gracefully:
- If
DirectoryPathis null or empty,Successwill befalseandCreatedPathwill be empty - If access is denied (
UnauthorizedAccessException),Successwill befalseandCreatedPathwill contain: "Error: Access denied - {exception message}" - If the path is invalid (
ArgumentException),Successwill befalseandCreatedPathwill contain: "Error: Invalid path - {exception message}" - If any other exception occurs,
Successwill befalseandCreatedPathwill contain: "Error: {exception message}"
Always check the Success output and review the CreatedPath for error messages if the operation fails.
Important Notes
- All parent directories are created automatically if they don't exist
- If the directory already exists, the operation succeeds without error
- The CreatedPath contains the full normalized path, which may differ from the input path
- Ensure the location has write permissions to create directories
- Use this activity before file operations to ensure the directory structure exists
Related Activities
- DeleteDirectory - Delete a directory
- CreateFile - Create a file in the directory
- CombinePath - Build directory paths