Code:
$timestamp = (Get-Date).ToString('yyyy-MM-dd')
$originalSource = Get-ChildItem "D:\output\csv\*.csv", "D:\output\csv\Billing\*.csv" | Where-Object {($_.LastWriteTime -ge [datetime]::today)}
$source = $originalSource
$target = "D:\output\csv\bin\$timestamp.7z"
$housekeepZipFile = "D:\output\csv\bin\*"
####Using 7z to zip
if (-not (test-path "D:\bin\7-Zip\7z.exe")) {throw "D:\bin\7-Zip\7z.exe needed"}
set-alias sz "D:\bin\7-Zip\7z.exe"
sz a -mx=0 -mhe=on -m0=lzma2 $target $source
I have tried above powershell. When i pumped files into csv and billing folder, it will create archive file that I want. When there is no today's date input file pumped into the csv and billing folder, 7zip random pull window files and create archive to me.
Question: How can I set that only create archive if there's a file with current date or create archive (with empty folder) if there no file with current date. P/S: I tried to put where-object to filter lastwritetime but seems not useful enough.