Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

How can I run 7zip in a loop using PowerShell?

$
0
0

Hi,

I am trying to use PowerShell to automate 7zip to compress all avi files in a folder.  I can get the command to run if I enter the command manually-

PS E:\dvtest> & "C:\Program Files (x86)\7zip\7za.exe" a -t7z -mx9 e:\DVzipped\20010101-20010202.avi.7z 20010101-20010202
.avi

7-Zip (A) 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
Scanning

Creating archive e:\DVzipped\20010101-20010202.avi.7z

Compressing  20010101-20010202.avi

But in order to automate the process, I must loop through a file collection and build the command using variables.  Here's an example-
PS E:\dvtest> $cmd1 = '"C:\Program Files (x86)\7zip\7za.exe" a -t7z -mx9 e:\DVzipped\'
PS E:\dvtest> $cmd1
"C:\Program Files (x86)\7zip\7za.exe" a -t7z -mx9 e:\DVzipped\
PS E:\dvtest> $command = $cmd1 + $f1 + $cmd2 + " " + $f1
PS E:\dvtest> $command
"C:\Program Files (x86)\7zip\7za.exe" a -t7z -mx9 e:\DVzipped\20010101-20010202.avi.7z 20010101-20010202.avi
PS E:\dvtest> & $command
& : The term '"C:\Program Files (x86)\7zip\7za.exe" a -t7z -mx9 e:\DVzipped\20010101-20010202.avi.7z
20010101-20010202.avi' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:3
+ & $command
+   ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: ("C:\Program Fil...01-20010202.avi:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I've tried a bunch of combinations, but none have worked so far.  It sure does look like the same command is being passed to the call operator.  Maybe I just don't understand how call operator works with strings.  Can someone please explain what is going on and how I can execute my 7zip command within a loop?

TIA


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>