본문 바로가기

Programing (프로그래밍)/WPF & C# (C Sharp)

WPF & C# (C Sharp) - 하위 폴더 검색기 ( 하위디렉토리 / 하위노드 / 재귀함수 )

728x90
반응형


 WPF & C# (C Sharp) - 하위 폴더 검색기 ( 하위디렉토리 / 하위노드 / 재귀함수 )


SearchDirectory.zip




MainWindow.xaml



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<Window x:Class="SearchDirectory.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="340.358" Width="683.666">
    <Grid>
        <Button Content="Search" HorizontalAlignment="Left" Margin="276.747,255.137,0,0" VerticalAlignment="Top" Width="118.76" Click="Button_Click" Height="51.119"/>
        <ListView x:Name="ListView01" HorizontalAlignment="Left" Height="190.542" Margin="10,59.595,0,0" VerticalAlignment="Top" Width="656">
            <ListView.View>
                <GridView>
                    <GridViewColumn/>
                </GridView>
            </ListView.View>
        </ListView>
        <TextBlock HorizontalAlignment="Left" Margin="10,10,0,0" TextWrapping="Wrap" Text="Search Directory" VerticalAlignment="Top" FontSize="24"/>
    </Grid>
</Window>
cs




MainWindow.xaml.cs


using System.IO;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
private void Button_Click(object sender, RoutedEventArgs e)
{
    ListView01.Items.Clear();
    string dir = @".\test\";
    dirSearch(dir);
}
// 폴더 체크
private void dirSearch(string dir)
{
    string[] Directories = Directory.GetDirectories(dir);   // Defalut Folder
    {
        string[] Files = Directory.GetFiles(dir);   // File list Search
        foreach (string fileName in Files)   // File check
        {
            ListView01.Items.Add(fileName);   // File add
        }
        foreach (string nodeDir in Directories)   // Folder list Search
        {
            ListView01.Items.Add(nodeDir);   // Folder add
            dirSearch(nodeDir);   // reSearch
        }
    }
}
 
cs



728x90
반응형