PSVersion 5.1.18362.2212
I would like to know if it is possible to read in a set of text files, modify their content and their filenames and store the results directly into a ZIP file?
The following reads text files in and modifies them, storing the change into a new file:
$xSource = "sourcefile.json"
$xTarget = "targetfile.json"
$replacement = "abc"
(Get-Content $xSource) | Foreach-Object {
$_.replace('[XX]', $replacement).`
} | Set-Content -path $xTarget
Is it possible to modify this to store the target file directly into a ZIP file?
I was hoping something like the following would work, but I am unsure of how I can pass the new filename through to the ZIP? or whether the following works at all?
$xSource = "sourcefile.json"
$xTarget = "targetfile.json"
$xTargetZip = "target.zip"
$replacement = "abc"
(Get-Content $xSource) | Foreach-Object {
$_.replace('[XX]', $replacement).`
} | Compress-Archive -Update -DestinationPath $xTargetZip
I get the impression that I would need to store the target files into a temporary folder and then pack them from there ... is there any way of avoiding a temporary folder?
Thanks in advance for any and all help.