The program needs to overwrite the backup file because of the project.
(The original solution is to use VB6 to traverse the file, do not spit slot)
Requirement 1: Check the modification time of each file, if it is less than the date parameter, then backup (and delete);
Requirement 2: Keep the directory structure of the backed up files.
Backing up files under Linux is simple, but we only have Windows Server.
Baidu is less than.
It took 2 hours to write a PowerShell script for performance ...
The words MS is basically rubbish compared with the open source scheme.
For example C # than Java, Windows Server than Linux, PowerShell than bash, etc...
1 Xargs solved the thing I have a TMD to write a loop.
Mdzz.
$scriptName = "Archive.ps1"; if (! ( $args. Count-eq 3) {write-host ("Usage-" + $scriptName + "<<source path>> <<destination Path>> ;
<<beforeDate>> ");
exit-1;
} $pathFrom = $args [0];
$pathTo = $args [1];
$dateBefore = [datetime]::P arseexact ($args [2], "YYYY-MM-DD", $null);
Write-host ("Source path is:" + $pathFrom);
Write-host ("Destination path is:" + $pathTo);
Write-host ("Archive files whose modified date is before:" + $dateBefore); if (! ( (Test-path-path $pathFrom)-and (Test-path-path $pathTo)) {write-host ("source path or destination path is not existed
!");
exit-1;
} $pathCopyTo = "";
$pathFromLen = $pathFrom. Length;
$LenGap = 0;
$LenGap 2 = 0; Ls-r $pathFrom |? {$_. Lastwritetime-lt $dateBefore} | foreach-object{$lenGap = $_. fullname.length-$pathFromLen-$_.
Name.length-1; $pathCopyTo = $PathTo + $_.
Fullname.substring ($pathFromLen, $LENGAP); Write-host ("copying" + $_.
FullName + "to" + $pathCopyTo); if (! ( TeSt-path-path $pathCopyTo)) {write-host ("Creating folder" + $pathCopyTo);
Mkdir-pa $pathCopyTo; } Copy-item $_.
FullName $pathCopyTo-force; } exit 0;