Skip to content

Wancoe/ZipTool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ZipTool

A command-line utility to create ZIP archives from directories with selective inclusion/exclusion of files and directories. Supports local file output, network file share destination, or email delivery via SMTP.

Features

  • Recursive directory traversal with selective filtering
  • Exclude by:
    • File extensions (e.g., .bmp, .jpg)
    • Directory names (e.g., .git, node_modules)
    • Specific filenames
  • Multiple output modes:
    • Local file system
    • Network file share (UNC paths)
    • Email via SMTP
  • Clean SOLID architecture with pluggable output providers
  • Fully commented code for educational purposes

Requirements

  • .NET 7.0 or later
  • Installed .NET SDK

Building

dotnet restore
dotnet build

Running

Local file output

dotnet run -- \
  --source "C:\folder\to\zip" \
  --zip "output.zip" \
  --output localFile \
  --target "C:\output\path" \
  --exclude-ext ".bmp,.jpg" \
  --exclude-dir ".git,node_modules" \
  --exclude-files "README.md,secret.txt"

Network file share

dotnet run -- \
  --source "C:\folder\to\zip" \
  --zip "output.zip" \
  --output filesShare \
  --target "\\server\share\path"

Email via SMTP

dotnet run -- \
  --source "C:\folder\to\zip" \
  --zip "output.zip" \
  --output smtp \
  --smtp-host "smtp.example.com" \
  --smtp-port 587 \
  --smtp-from "sender@example.com" \
  --smtp-to "recipient@example.com" \
  --smtp-ssl true \
  --smtp-user "username" \
  --smtp-password "password"

Running Tests

dotnet run --project ZipTool.Tests\ZipTool.Tests.csproj

Expected output:

RunCreateZipTest passed.
RunParseOptionsTest passed.
All tests passed.

Project Structure

├── Program.cs                          # Main entry point & flow
├── Core/
│   ├── CommandLineOptions.cs           # Argument parser & validation
│   ├── ZipService.cs                   # ZIP creation logic
│   └── Outputs/
│       ├── IOutputProvider.cs          # Interface for output strategies
│       ├── OutputManager.cs            # Dispatcher for output modes
│       ├── LocalFileOutputProvider.cs  # Save to local disk
│       ├── FileShareOutputProvider.cs  # Save to network share
│       └── SmtpOutputProvider.cs       # Send via email
└── ZipTool.Tests/
    └── Program.cs                      # Console-based test harness

Architecture Notes

Design Patterns Used:

  • Strategy Pattern: Output providers implement IOutputProvider interface
  • Factory/Dispatcher: OutputManager selects provider based on OutputMode
  • Dependency Injection (manual): Services passed to orchestrator

Why This Design: Adding a new output method (e.g., AWS S3, FTP) requires:

  1. Implementing IOutputProvider in a new file
  2. Adding new case to OutputManager.Publish()

No changes to core ZIP logic needed.

Key C# Features Demonstrated

  • Record types (CommandLineOptions with required fields)
  • Nullable reference types (string?, #nullable enable)
  • Extension methods & LINQ
  • IDisposable pattern for resource cleanup
  • Sealed classes for security & optimization

Common Interview Questions Addressed

Q: How would you add a new output format?
A: Implement IOutputProvider, add case to OutputManager switch statement.

Q: How do you handle file exclusions?
A: Recursive predicate checks in IsDirectoryExcluded() and IsFileExcluded().

Q: Why use interfaces over inheritance?
A: Decouples output concerns, easier testing, supports composition over inheritance.

Notes for Technical Interviews

  • Code is heavily commented for readability (transition from Python to C#)
  • Error handling: Validation in CommandLineOptions.Parse(), exception propagation
  • Testing: Manual console harness (avoid test framework compatibility issues)
  • Framework: .NET 7.0 for stability; upgradeable to .NET 8 or 10

Author: Created for technical interview exercise
Language: C# 14
Platform: .NET 7.0+

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages