Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


If else

 
Logged in as: Guest
arrSession:exec spGetSession 2,5,54265
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Windows PowerShell >> If else
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 If else - 12/12/2007 9:08:48 PM   
  spooter

 

Posts: 15
Score: 0
Joined: 11/14/2007
Status: offline
Hi all,

I have a variable called $accepted which contains a list of files I want to move, the below code works if the files exist and get stored but if no files are found making $accepted empty I get a error.  I want the script to do something if the files exist but if its empty, write no files found.  I cant understand why this doesnt work.

if ($accepted -eq $null) {write No Files found}
else {Move-Item $accepted e:\Team_Upload\} 

The items get moved if they exist but if not I get the error

Move-Item : Cannot bind argument to parameter 'Path' because it is an empty array.
ERROR: At line:74 char:16
ERROR: + else {Move-Item <<<< $accepted e:\Team_Upload\}
ERROR: Get-ChildItem : An object at the specified path E:\ does not exist.
 
 
Post #: 1
 
 RE: If else - 12/13/2007 1:39:08 AM   
  ebgreen


Posts: 4411
Score: 29
Joined: 7/12/2005
Status: offline
Could you post all of your code? How is $accepted created?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to spooter)
 
 
Post #: 2
 
 RE: If else - 12/13/2007 7:03:03 PM   
  spooter

 

Posts: 15
Score: 0
Joined: 11/14/2007
Status: offline
Hi Thanks for the reply,

The code I used was

dir e:\Files -include *.xls,*.doc rec | where {($_.Name).toUpper() -match [regex]"^[1-9]...GRP"} -OutVariable accepted
 
Regards

(in reply to spooter)
 
 
Post #: 3
 
 RE: If else - 12/14/2007 5:54:19 AM   
  SAPIENScripter


Posts: 261
Score: 2
Joined: 11/1/2006
From: SAPIEN Technologies
Status: offline
Because $accepted is an array, you could check $accepted.count.  There is also an operator -contains which you can use to see if a specific item exists in the array.

_____________________________

Jeffery Hicks
Windows PowerShell MVP
SAPIEN Technologies - Scripting, Simplified. www.SAPIEN.com

(in reply to spooter)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Windows PowerShell >> If else Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts