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)
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.
|
|
|
|
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)
Could you post all of your code? How is $accepted created?
|
|
|
|
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)
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
|
|
|
|
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)
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.
|
|
|
|