Filtering and copying with preserving folder structure

Phong Bach 0 Reputation points
2024-02-15T10:14:59.76+00:00

Hi everyone, We need to manage backup for a set of folders in a Windows Server 2019 without knowing where new files locates. Backup destination does not work with well-known backup applications so we need to copy manually to it. We are finding a script or tools to filter and copy only files in a certain date range and paste them to destination while preserving folder structure. Folders without update should be empty or at least does not appear in destination. If anyone has experience about that, please share your idea. Thanks in advance. Mountaineer

Windows for business Windows Client for IT Pros User experience Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. degngo 15 Reputation points
    2024-02-25T13:02:05.3833333+00:00

    Try PowerShell with Get-ChildItem: Here's a basic example and this should be more versatile, easier to customize :

    $sourceDir = "C:\YourSourceFolder"
    $destDir = "C:\YourDestinationFolder"
    $startDate = "2024-02-01"
    $endDate = "2024-02-25"
    
    Get-ChildItem -Path $sourceDir -Recurse -Filter "*.*" | Where-Object { $_.LastWriteTime -ge $startDate -and $_.LastWriteTime -le $endDate } | ForEach-Object { Copy-Item -Path $_.FullName -Destination $destDir -Recurse -IncludeSubdirectories }
    
    # Explanation:
    # Get-ChildItem: Lists files and folders
    # -Path: Specifies the source directory
    # -Recurse: Includes subfolders
    # -Filter: Filters files by name
    # Where-Object: Filters files by date range
    # Copy-Item: Copies files to the destination
    # -Path: Specifies the source file
    # -Destination: Specifies the destination directory
    # -Recurse: Includes subfolders
    # -IncludeSubdirectories: Copies empty subfolders
    

    Also , There are some copy tools that have user-friendly interfaces, additional features and meets your requirements , Consider tools like FreeFileSync, Gs Richcopy 360 , SyncBack, or Beyond Compare.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.