2

I am using a Powershell script to compress some files into a .zip file. My entire script looks like this:

Write-Host "Creating Zip File... " -NoNewLine
write-zip ("file1.txt", "file2.txt", "file3.txt", "logs") log.zip
Write-Host "Done"

This script is in a file named compress.ps1. When I am at a command line prompt, I can enter powershell -file compress.ps1 and it works perfectly. However, if I attempt to run the script from the "Windows PowerShell ISE", it doesn't work. The prompts ("Creating Zip File", and "Done") are shown. However, I don't see the .zip file on my file system. This same problem happens if I just right-click on compress.ps1 from Windows Explorer and choose to Open With Windows PowerShell.

What am I doing wrong? Thank you for any insights you can provide!

Ryan Ries
  • 55,481
  • 10
  • 142
  • 199
user26712
  • 329
  • 1
  • 4
  • 10
  • Oh, and mind your working directory too. Try specifying the fully qualified path names of the files instead of just their short names and see what happens. – Ryan Ries Aug 01 '13 at 17:03
  • Ah... the working directory was the issue. Just out of curiosity, is there a way to use a relative path? I'm new to PowerShell. i'd like the file to just appear in the directory that I run the script from. I'm not sure how to do a relative path in PowerShell though. – user26712 Aug 01 '13 at 17:24
  • "$PWD\log.zip" as well as including $PWD in the file names in the list. – Etan Reisner Aug 01 '13 at 17:25

1 Answers1

1

Mind your working directory too. Try specifying the fully qualified path names of the files instead of just their short names and see what happens.

Ryan Ries
  • 55,481
  • 10
  • 142
  • 199