[积累]遍历目录下的全部文件

            

知识点:System.IO.DirectoryInfo.GetFiles() + 3次重载,foreach  

参见:ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.NETDEVFX.v20.chs/cpref8/html/O_T_System_IO_DirectoryInfo_GetFiles.htm

示例代码

                //DirectoryInfo & Files search
                DirectoryInfo dirInfo = new DirectoryInfo( "yourpath" );
                //Search Files & Deal with Exception
                FileInfo[] fis;
                try
                {
                    fis = dirInfo.GetFiles();
                }
                catch ( DirectoryNotFoundException e )
                {
                    MessageBox.Show( e.Message );
                    return;
                }
                //For each file 
                foreach ( FileInfo File in fis )
                {     

                     //Do something you like 

                 }                                                                                  

你可能感兴趣的:([积累]遍历目录下的全部文件)