Zipping files with the same file name.

by May 2, 2018

Hi Guys

Any ideas how i can ZIP a .txt file and have the zip file the same name as the .txt  (hope that makes sense :-)? i have written a script to ZIP a file and rename the zip to a specific file name but in this case i need the ZIP file to be the same name as the txt?

i.e text file is called. TODAYSFILE.YYYYMMDD

Below scripts works fine…. Zips and renames ok… 

#Function to call 7ZIP
function create-7zip([String] $aDirectory, [String] $aZipfile){
[String]$pathToZipExe = "C:temp1234567897za.exe";
[Array]$arguments = "a", "-tzip", "$aZipfile", "$aDirectory";
& $pathToZipExe $arguments;}

#File Variables
$tp_file = "<<source>>TODAYSFILE.YYYYMMDD" -f $d
$tp_arc_file = "<<source>>" -f $d

If (Test-Path -Path $tp_file) {
create-7zip $tp_file $tp_arc_file
Else {
"Extract files for todays date do not exist"

Any help will be much appreciated.

Thanks all.