zoukankan      html  css  js  c++  java
  • Get Files from Directory




     

    File Structure

    Get Files from Directory [C#]

    This example shows how to get list of file names from a directory (includingsubdirectories). 

    You can filter the list by specific extension.


    To get file names from the specified directory, use static method 

    Directory.Get­Files

    Lets have these files andsubfolders in „c:MyDir“ folder:


    Get files from directory

    Method Directory.GetFiles returns string array with files names (fullpaths).

    [C#]
     using System.IO;  

       string[] filelist = Directory.GetFiles(@"D:迅雷下载");
                foreach (var f in filelist)
                    richTextBox1.AppendText(f + " ");  

     

    Get files from directory (with specified extension)

    You can specify search pattern. You can use wildcard specifiers in the searchpattern, 

    e.g. „*.bmp“ to select files with the extension or „a*“ toselect files beginning with letter „a“.

    [C#]

                string[] filelist = Directory.GetFiles(@"D:迅雷下载","*.zip");
                foreach (var f in filelist)
                    richTextBox1.AppendText(f + " "); 
     
    获得文件夹下的指定文件列表(只找一层)

     

    Get files from directory (including all subdirectories)

    If you want to search also in subfolders use parameterSearchOption.A­llDirectories.

    [C#]

                string[] filelist = Directory.GetFiles(@"D:迅雷下载""*.*",SearchOption.AllDirectories);
                foreach (var f in filelist)
                    richTextBox1.AppendText(f + " ");

     
     





  • 相关阅读:
    C# Workbook读取Execl数据
    C# Task
    Json/XML序列化和反序列化
    C# RSA加解密和MD5加密
    SqlServer基本操作
    SQL Server基础优化
    Http请求基本方法
    ASP.NET MVC基础知识
    简单的五险一金计算器
    PHP基础入门(三)
  • 原文地址:https://www.cnblogs.com/xe2011/p/3802384.html
Copyright © 2011-2022 走看看