1. Get the list of all files in the directory recursively
Call:
list<string> fileList = getfilelist (path);
Method
Private Staticlist<string> Getfilelist (stringpath) {List<string> fileList =Newlist<string>(); if(directory.exists (path) = =true) { foreach(stringFileinchdirectory.getfiles (path)) {filelist.add (file); } foreach(stringDirectoryinchdirectory.getdirectories (path)) {Filelist.addrange (getfilelist (directory)); } } returnfileList; }
2. List of files under non-recursive access directory
Staticlist<string> fileList1 =Newlist<string>(); Private Static voidGetFileList1 (stringpath) { if(directory.exists (path) = =true) { foreach(stringFileinchdirectory.getfiles (path)) {filelist1.add (file); } foreach(stringDirectoryinchdirectory.getdirectories (path)) {GetFileList1 (directory); } } }
View Code
C # get List of all files under directory