Interactive CLI for selective file copying with content preview. Built with Java 25 as a single-file unnamed class.
# Interactive mode
java ZFSL.java
# Command line mode
java ZFSL.java -s ./src -t ./backup -e .java-s, --source <directory> Source directory (default: current directory)
-t, --target <directory> Target directory (prompts if not provided)
-e, --extension <extension> File extension filter (prompts if not provided)
-h, --help Display help
For each discovered file:
- Preview first 20 lines with metadata (size, last modified)
- Choose:
y(copy),n(skip), orq(quit) - Confirm overwrite if target file exists
- View operation summary with detailed error report
Requirements: Java 25+
Design:
- Single file unnamed class
- Zero dependencies (Java SE only)
- Records for immutable data (
Config,ProcessingState) - Sealed interfaces for type-safe result handling (
OperationResult,UserAction) - Pattern matching in switch expressions
- Text blocks for multi-line output
Key Components:
Config: Validates source/target directories and normalizes file extensionsOperationResult: Success/Skip/Error outcomes with detailed contextProcessingState: Tracks file counts and results, formats summary reportsUserAction: Copy/Skip/Quit decisions from user input
File Operations:
- Recursive discovery via
Files.walk() - Flat copy structure (no subdirectories preserved)
- Overwrites only with explicit confirmation
- Specific error messages for
AccessDeniedException,FileSystemException, etc.
# Copy Java files from src to backup
java ZFSL.java -s ./src -t ./backup -e .java
# Interactive selection from current directory
java ZFSL.java -t ./output -e txt