header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Passing Directory list into an Array
Last Post 08 Feb 2010 02:10 PM by Shay Levy. 3 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
BobdeeUser is Offline
Basic Member
Basic Member
Posts:130
Avatar

--
08 Feb 2010 07:50 AM
    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.
    George HowarthUser is Offline
    Basic Member
    Basic Member
    Posts:360
    Avatar

    --
    08 Feb 2010 08:20 AM
    Try this:

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

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

    --
    08 Feb 2010 08:46 AM
    Brilliant - thanks
    Shay LevyUser is Offline
    PowerShell MVP, Admin
    Veteran Member
    Veteran Member
    Posts:1362
    Avatar

    --
    08 Feb 2010 02: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://PowerShay.com
    PowerShell Community Toolbar
    Twitter: @ShayLevy
    You are not authorized to post a reply.


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