Displaying the result of gci in a list

Mar 1, 2013 at 6:25 PM
I want to display a list of files matching a particular expression. I can't figure out how to do it in ShowUI. Please help. Here is my attempt so far.

It is based on the twitter feed example.
Import-Module ShowUI

# use get childchilditem to search recursively for filenames containing the searchstring
function FindMatchingFileNames($searchstring){
    gci C:\users\myUser -r -i "*$searchstring*" 
}

# variable containing window parameters
$ws = @{
    WindowStartupLocation = "CenterScreen"
    Height = 550
}

New-Window -SizeToContent width @ws -Show{
    ListBox -Background Black -ItemTemplate {
    Grid -Columns 300, 300 {
            TextBlock -Name FileName -Margin 5 -Column 0 -TextWrapping Wrap -Foreground White
            TextBlock -Name FullFileName -Margin 5 -Column 1 -TextWrapping Wrap -Foreground White
        } |
            ConvertTo-DataTemplate -binding @{
                "FileName.Text" = "name"
                "FullFileName.Text" = "fullname" 
            } 
    } -ItemsSource (FindMatchingFileNames "partial string")
}
Developer
Mar 2, 2013 at 1:05 PM
Edited Mar 2, 2013 at 1:05 PM
Your example works for me. I changed the directory and the search string.

What are you encountering?
ipmo showui

# use get childchilditem to search recursively for filenames containing the searchstring
function FindMatchingFileNames($searchstring){
    gci C:\temp -Recurse -Include "*$searchstring*" 
}

# variable containing window parameters
$ws = @{
    WindowStartupLocation = "CenterScreen"
    Height = 550
}

New-Window -SizeToContent width @ws -Show{
    ListBox -Background Black -ItemTemplate {
    Grid -Columns 300, 300 {
            TextBlock -Name FileName -Margin 5 -Column 0 -TextWrapping Wrap -Foreground White
            TextBlock -Name FullFileName -Margin 5 -Column 1 -TextWrapping Wrap -Foreground White
        } |
            ConvertTo-DataTemplate -binding @{
                "FileName.Text" = "name"
                "FullFileName.Text" = "fullname" 
            } 
    } -ItemsSource (FindMatchingFileNames "ps1")
}