If else

Author Message
spooter

  • Total Posts : 17
  • Scores: 0
  • Reward points : 0
  • Joined: 11/14/2007
  • Status: offline
If else Wednesday, December 12, 2007 10:08 PM (permalink)
0
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.
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    RE: If else Thursday, December 13, 2007 2:39 AM (permalink)
    0
    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
     
    #2
      spooter

      • Total Posts : 17
      • Scores: 0
      • Reward points : 0
      • Joined: 11/14/2007
      • Status: offline
      RE: If else Thursday, December 13, 2007 8:03 PM (permalink)
      0
      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
       
      #3
        SAPIENScripter

        • Total Posts : 283
        • Scores: 2
        • Reward points : 0
        • Joined: 11/1/2006
        • Location: SAPIEN Technologies
        • Status: offline
        RE: If else Friday, December 14, 2007 6:54 AM (permalink)
        0
        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

        Follow Me: http://www.twitter.com/JeffHicks
         
        #4

          Online Bookmarks Sharing: Share/Bookmark

          Jump to:

          Current active users

          There are 0 members and 1 guests.

          Icon Legend and Permission

          • 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
          • Read Message
          • Post New Thread
          • Reply to message
          • Post New Poll
          • Submit Vote
          • Post reward post
          • Delete my own posts
          • Delete my own threads
          • Rate post

          2000-2012 ASPPlayground.NET Forum Version 3.9