Can you call Directory.GetFiles() with multiple filters?

前端 未结 26 2455
逝去的感伤
逝去的感伤 2020-11-22 05:25

I am trying to use the Directory.GetFiles() method to retrieve a list of files of multiple types, such as mp3\'s and jpg\'s. I have t

26条回答
  •  被撕碎了的回忆
    2020-11-22 05:58

    Nope. Try the following:

    List _searchPatternList = new List();
        ...
        List fileList = new List();
        foreach ( string ext in _searchPatternList )
        {
            foreach ( string subFile in Directory.GetFiles( folderName, ext  )
            {
                fileList.Add( subFile );
            }
        }
    
        // Sort alpabetically
        fileList.Sort();
    
        // Add files to the file browser control    
        foreach ( string fileName in fileList )
        {
            ...;
        }
    

    Taken from: http://blogs.msdn.com/markda/archive/2006/04/20/580075.aspx

提交回复
热议问题