4

I need to execute something like

7za e $file_path -oC:\Destination

inside a powershell script, but substitute destination folder (C:\Destination) with a variable. Some like:

7za e $file_path -o$output_path

which obviously does not work. The previous statement in fact creates a folder with actual name $output_path

How can this be done?

6

I think this should work, but it doesn't for me for some reason:

7za e $file_path -o$($output_path)

This will work:

$outparam = "-o" + $output_path
7za e $file_path $outparam

This will also work (it's just condensing the previous one into one line):

7za e $file_path $("-o" + $output_path)
2
  • 1
    Thanks! That also works -> & 7za e $file_path "-o${output_path}". I just needed those quotes.
    – lalibi
    Mar 10 '12 at 11:55
  • Third option works great. You rock! Dec 1 '17 at 18:21
0

I found a solution to overcome this but I would still like to now if there any other way to do it.

Push-Location ($output_path)
& 7za e $file_path
Pop-Location

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.