Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
1
Indexable
Never
param (
    [Parameter(Mandatory=$true, Position=0)]
    [ValidateScript({Test-Path $_ -PathType Container})]
    [string]$dir1,

    [Parameter(Mandatory=$true, Position=1)]
    [ValidateScript({Test-Path $_ -PathType Container})]
    [string]$dir2,

    [Parameter(Mandatory=$true, Position=2)]
    [string]$ext,

    [Parameter(Mandatory=$true, Position=3)]
    [string]$zipname
)

# Check if the first directory exists, and create it if it doesn't
if (-not (Test-Path $dir1 -PathType Container)) {
    New-Item -ItemType Directory -Path $dir1 | Out-Null
}

# Change to the first directory
Set-Location -Path $dir1

# Check if the second directory exists
if (-not (Test-Path $dir2 -PathType Container)) {
    Write-Error "Directory '$dir2' does not exist."
    exit 1
}

# Copy all files with the specified extension from the second directory to the first directory
Get-ChildItem -Path $dir2 -Filter "*.$ext" -Recurse -File | ForEach-Object {
    Copy-Item -Path $_.FullName -Destination $dir1
}

# Compress the files into a single .zip file
Compress-Archive -Path "$dir1\*.$ext" -DestinationPath "$dir1\$zipname.zip"

# Terminate with exit code 0
exit 0