遍历某目录下的所有文件的方法//遍历方法(C#) private void LookupFiles( DirectoryInfo dir ) { FileInfo[] files = dir.GetFiles(); //files是这个目录下的所有文件 DirectoryInfo[] subDirs = dir.GetDirectories(); if( subDirs!=null && subDirs.Length!=0 ) for( int i=0;i<subDirs.Length;i++ ) LookupFiles( subDirs[i] );// 递归遍历子目录 } 使用的时候: DirectoryInfo dir = new DirectoryInfo("要遍历的根目录"); LookupFiles( dir ); //遍历它的所有子目录和文件--------------------------------------------------------------------------------//遍历方法(VB.net) Sub SearchDirectory(ByVal Dir As String) Dim Dirs,Files As String() Dim s As String Debug.WriteLine("Searching Folder """ + Dir + """...") Files = System.IO.Directory.GetFiles(Dir) ForEach s In Files Debug.WriteLine(" " + s) Next Dirs = System.IO.Directory.GetDirectories(Dir) ForEach s In Dirs SearchDirectory(s) Next End Sub
原文链接:https://www.f2er.com/vb/262420.html