header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

We have a new sponsor!  Introducting Pragma Systems.  See the home page for details.

Passing Directory list into an Array
Last Post 08 Feb 2010 10:10 PM by Shay. 3 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
08 Feb 2010 03:50 PM  
Can anyone help??

I'm trying to pass all the subfolders in a directory in an array, then (for example) create a file in each of the directories.

Unfortunately, rather than doing this the set-location is falling over as the array is passing more than i anticipated into it.  So I recieve an error "Cannot find path '......\@{Name=RobLog}' because it does not exist"

Can anyone tell me how to pass an array into a set-location.  Here's what I am using.

$dirs = dir | where {$_.PsIsContainer} | select name
 
foreach ($dir in $dirs) {

Set-Location $dir
New-Item "robbie.txt" -type file

}

Thanks.

Rob.
GWHowarth88User is Offline
Basic Member
Basic Member
Posts:348
Avatar

--
08 Feb 2010 04:20 PM  
Try this:

$dirs = dir | where {$_.PsIsContainer}

foreach ($dir in $dirs)
{
Set-Location $dir.fullname
New-Item "robbie.txt" -type file
}
bobdee1980User is Offline
New Member
New Member
Posts:63
Avatar

--
08 Feb 2010 04:46 PM  
Brilliant - thanks
ShayUser is Offline
Veteran Member
Veteran Member
Posts:1136
Avatar

--
08 Feb 2010 10:10 PM  
You an cretae tefile without setting location:

dir | where {$_.PsIsContainer} | new-item -type file -path {$_.fullname} -name robbie.txt

Shay Levy
Windows PowerShell MVP
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell Community Toolbar
Twitter: @ShayLevy
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer