# Read entire fileread_file:configdopathvalue("/etc/config.json")end# Using inputs/resultsread_file:user_datadopathinput(:file_path)end
Writing Files
# Write simple contentwrite_file:outputdopathinput(:output_path)contentvalue("Hello, World!")end# Write with revert capabilitywrite_file:backupdopathinput(:backup_path)contentresult(:processed_data)revert_on_undo?trueend
Copying Files
# Copy single filecp:backup_filedosourceinput(:source_path)destinationinput(:dest_path)end# Copy recursivelycp_r:backup_directorydosourceinput(:source_dir)destinationinput(:backup_dir)end
Directory Operations
Creating Directories
# Create single directorymkdir:new_dirdopathinput(:new_directory_path)end# Create with parentsmkdir_p:deep_pathdopathinput(:deep_directory_path)revert_on_undo?trueend
File Discovery
# Find files by patternglob:txt_filesdopatterninput(:search_pattern)end# Include hidden filesglob:all_configsdopatternvalue("/etc/**/*.conf")match_dottrueend
Removing Files
# Remove single filerm:temp_filedopathinput(:file_to_remove)end# Remove directoryrmdir:empty_dirdopathinput(:directory_to_remove)end
File I/O Operations
File Handles
# Open file for readingopen_file:file_handledopathinput(:data_file_path)modes[:read]end# Open for writingopen_file:output_handledopathinput(:log_file_path)modes[:write,:append]end# Close when doneclose_file:cleanupdofileresult(:file_handle)end
Stream Reading
# Read as linesio_stream:linesdofileresult(:file_handle)end# Binary streamingio_binstream:chunksdofileresult(:binary_handle)line_or_bytes4096end
Direct I/O
# Read specific amountio_read:chunkdofileresult(:file_handle)length1024end# Write to file handleio_write:append_datadofileresult(:output_handle)datainput(:log_message)end
File Metadata
File Information
# Get file statsstat:file_infodopathinput(:target_file)end# Get link stats (doesn't follow symlinks)lstat:link_infodopathinput(:symlink_path)end# Read symlink targetread_link:targetdopathinput(:symlink_path)end
Creating Links
# Hard linkln:hard_linkdoexistinginput(:original_file)newinput(:hardlink_path)end# Symbolic linkln_s:soft_linkdoexistinginput(:original_file)newinput(:symlink_path)end
Permissions & Ownership
Changing Permissions
# Set file permissionschmod:make_executabledopathinput(:script_path)modevalue(0o755)end# Use template for dynamic permissionschmod:set_permsdopathinput(:file_path)modeinput(:permission_mode)revert_on_undo?trueend
# Create backup with metadata preservationstat:original_statsdopathinput(:source_file)endcp:backup_filedosourceinput(:source_file)destinationinput(:backup_path)endwrite_stat:preserve_metadatadopathinput(:backup_path)statresult(:original_stats)end
File Validation
# Check file exists and is readablestat:validate_sourcedopathinput(:source_path)endstep:check_permissionsdoargument:stat,result(:validate_source)runfn%{stat:%{access:access}},_context->if:readinaccessdo{:ok,:valid}else{:error,"File not readable"}endendend
# Operations that can be revertedmkdir_p:temp_workspacedopathinput(:workspace_path)revert_on_undo?trueendwrite_file:temp_datadopathinput(:workspace_path),transform:&Path.join(&1,"data.json")contentinput(:json_data)revert_on_undo?trueendchmod:secure_tempdopathinput(:workspace_path)modevalue(0o700)revert_on_undo?trueend