A Python utility to copy only modified files from a source directory to a target directory based on modification date, with powerful filtering capabilities.
- Date-based filtering: Copy only files modified after a specific date
- Directory structure preservation: Maintains original folder hierarchy
- Flexible filtering:
- Exclude specific directories (e.g., node_modules, .git)
- Exclude file types by extension (e.g., .log, .tmp)
- Include only specific file types
- Exclude specific files by name
- Automatic directory creation: Creates target directories as needed
- Overwrite support: Replaces existing files in target
- Progress tracking: Shows what's being copied
- Summary report: Displays statistics after completion
- Python 3.6 or higher
- No external dependencies (uses only standard library)
- Download or clone the script files to a directory
- Ensure you have Python 3 installed:
python --version
Edit config.json to set up your copy operation:
{
"source_dir": "C:/path/to/your/source/folder",
"output_dir": "C:/path/to/your/output/folder",
"day": 1,
"month": 1,
"year": 2026,
"exclude_dirs": [...],
"exclude_extensions": [...],
"include_extensions": [],
"exclude_files": [...]
}- source_dir: Full path to the source directory to scan
- output_dir: Full path to the target directory where files will be copied
- day: Day of the month (1-31)
- month: Month of the year (1-12)
- year: Full year (e.g., 2026)
- Files modified after this date (year-month-day) will be copied
- Example:
"day": 15, "month": 12, "year": 2025= files after December 15, 2025
-
exclude_dirs: Array of directory names to skip
- Example:
["node_modules", ".git", "dist", "build"] - Matches on directory name only, not full path
- Example:
-
exclude_extensions: Array of file extensions to skip
- Include the dot (e.g.,
".log",".tmp") - Case-insensitive matching
- Example:
[".log", ".tmp", ".cache", ".pyc"]
- Include the dot (e.g.,
-
include_extensions: Array of file extensions to include
- If specified, ONLY these extensions will be copied
- Overrides exclude_extensions
- Leave empty
[]to allow all extensions (except excluded ones) - Example:
[".py", ".js", ".ts", ".jsx"]
-
exclude_files: Array of specific filenames to skip
- Exact filename match (case-sensitive)
- Example:
["package-lock.json", "yarn.lock", ".env.local"]
- Edit
config.jsonwith your settings - Run the script:
python diff_copy.py
python diff_copy.py my-custom-config.jsonCopy only Python files modified after January 1, 2024:
{
"source_dir": "C:/projects/myapp",
"output_dir": "C:/backups/myapp-changes",
"modified_after_date": "2024-01-01",
"exclude_dirs": ["__pycache__", ".git", "venv"],
"exclude_extensions": [".pyc", ".pyo"],
"include_extensions": [".py"],
"exclude_files": []
}Copy all modified files but exclude logs and temporary files:
{
"source_dir": "C:/projects/webapp",
"output_dir": "C:/deployment/webapp",
"modified_after_date": "2024-12-01",
"exclude_dirs": ["node_modules", "dist", ".git"],
"exclude_extensions": [".log", ".tmp", ".cache"],
"include_extensions": [],
"exclude_files": ["package-lock.json", ".env.local"]
}Copy source code files modified in the last week:
{
"source_dir": "C:/dev/myproject",
"output_dir": "C:/reviews/myproject-recent",
"modified_after_date": "2024-12-25",
"exclude_dirs": ["bin", "obj", "packages", ".vs"],
"exclude_extensions": [".exe", ".dll", ".pdb", ".suo"],
"include_extensions": [".cs", ".csproj", ".sln", ".config"],
"exclude_files": []
}======================================================================
DIFF COPY SCRIPT
======================================================================
Source Directory: C:/projects/myapp
Output Directory: C:/backups/myapp-changes
Modified After: 2024-01-01
======================================================================
Scanning files...
✓ Copied: src/main.py
✓ Copied: src/utils/helper.py
✓ Copied: tests/test_main.py
✓ Copied: config/settings.json
======================================================================
SUMMARY
======================================================================
Files Processed: 156
Files Copied: 4
Files Skipped: 152
Errors: 0
======================================================================
Output directory: C:/backups/myapp-changes
Done!
- Load Configuration: Reads and validates
config.json - Parse Date: Converts the date string to a datetime object
- Scan Directory: Walks through all files in the source directory
- Apply Filters: For each file:
- Checks if in excluded directory
- Checks modification date
- Checks file extension filters
- Checks specific file exclusions
- Copy Files: Copies matching files while preserving directory structure
- Report: Shows summary of operation
- Make sure
config.jsonexists in the same directory as the script - Or specify the full path:
python diff_copy.py C:/path/to/config.json
- Check that the
source_dirpath in config.json is correct - Use forward slashes
/or escaped backslashes\\in paths
- Use format:
YYYY-MM-DDorYYYY-MM-DD HH:MM:SS - Example:
"2024-01-01"or"2024-01-01 14:30:00"
- Check that files were actually modified after the specified date
- Verify your filter settings aren't too restrictive
- Make sure
include_extensionsis empty[]if you want all file types
- Run the script with appropriate permissions
- Check that you have read access to source and write access to output directory
-
Test First: Start with a small source directory to verify your filters work correctly
-
Include vs Exclude: If you specify
include_extensions, only those file types will be copied (ignoreexclude_extensions) -
Date Formats: The script accepts both date-only and date-time formats
-
Path Separators: Use forward slashes
/in paths for cross-platform compatibility -
Backup: Consider backing up your target directory before running if it contains important files
This script is provided as-is for free use and modification.