4

Right now my server service is calling 7za to extract archive files like this:

7za x "file" -o"output folder"

There's problem due to a server compliance Windows cleaning service that purges all files that are older than one hour in the Output folder. Making changes to the service is not not option either.

All files in the Output folder are deleted automatically every one minute so sometimes even users that extract to this folder cannot access the file(s) extracted due to timing and the clean process running once every one minute.

Question: Is there a switch to tell 7zip to set the Modified time of extracted file(s) to [now] the current time instead of the time of the files within the archive?

Luke Vo
  • 1,793

1 Answers1

3

As a workaround approach to this problem it's possible to change the date modified attributes of the files once they are extracted to a temp location and then move them afterwards.

You could extract the files to a temp folder via 7za, adjust the date modified values of the extracted files to be the current date time stamp, move them over to the final destination, and then cleanup the temp files/folder.

Just set the full path location of the archive file with the $file variable value. Also, set the full path location of the final destination folder with the $dest variable value pointing it to the location that has the service which purges files within it every one minute older than a certain age.

PowerShell

$file = "C:\Folder\Path\File.zip"
$dest = "C:\Final\Destination\FolderPath"
$now = Get-Date
$nowf = "$($Env:Temp)\$((Get-Date).ToString("yyyyMMdd_hhssmmmtt"))"

New-Item -ItemType Directory -Force -Path $nowf Start-Process "C:\Program Files\7-Zip\7za.exe" -ArgumentList "x $file -o$nowf" -NoNewWindow -Wait

$i = Get-ChildItem -Path $nowf -File -Recurse $i | % { Process { If (Test-Path $.FullName){ Set-ItemProperty -Path $.FullName -Name LastWriteTime -Value $now Copy-Item -Path $_.FullName -Destination $dest -Force }
}}; Remove-Item -Path "$nowf" -Force -Recurse;

Supporting Resources