. Net built-in types include fileinfo and directoryinfo, which are used to operate files and folders. Different from file and directory, fileinfo and directoryinfo are mainly used to operate structures in files and folders, such as creation, copying, reading information, moving, determining whether there is, deleting, and other functions
1 static void readfileinfo (fileinfo FI) 2 {3 console. writeline ("filename:" + fi. name); 4 console. writeline ("filedirectoryname:" + fi. directoryname); 5 console. writeline ("filelength:" + fi. length); 6 console. writeline ("filecreationtime" + fi. creationtime); 7 console. writeline ("filelastwritetime" + fi. lastwritetime); 8 console. writeline ("filelastaccesstime" + fi. lastaccesstime); 9 console. writeline ("filef Ullname "+ fi. fullname); 10 console. writeline ("fileextension" + fi. extension); 11} 12 13 static void readdirectoryinfo (directoryinfo di) 14 {15 console. writeline ("directoryname:" + di. name); 16 console. writeline ("directoryparentname:" + di. parent. name); 17 console. writeline ("directorylastwritetime:" + di. lastwritetime); 18 console. writeline ("directorylastaccesstime:" + di. lastaccesstime); 19 console. writelin E ("directoryfullname:" + di. fullname); 20 fileinfo [] Fi = di. getfiles (); 21 foreach (fileinfo fi in FD) 22 readfileinfo (FI); 23 directoryinfo [] Dis = di. getdirectories (); 24 foreach (directoryinfo NDI in DIS) 25 readdirectoryinfo (NDI); 26} 27 28 static void directorytest () 29 {30 directoryinfo di = NULL; 31 try32 {33 di = new directoryinfo ("C: \ test"); 34 di. create (); 35 di. createsubdirectory ("subdi"); 36 f Ileinfo info = new fileinfo ("C: \ test \ subdi \ test.txt"); 37 using (filestream FS = info. create () {} 38 readdirectoryinfo (DI); 39 di. moveTo ("C: \ Test2"); 40} 41 finally 42 {43 If (Di! = NULL) 44 {45 // Delete the folder 46 // delete the file and subfolders together 47 di. delete (true); 48} 49} 50} 51 52 static void filetest () 53 {54 fileinfo info = NULL; 55 fileinfo newinfo = NULL; 56 try57 {58 info = new fileinfo ("C: \ test1.txt"); 59 using (filestream FS = info. create () {} 60 readfileinfo (Info); 61 info. moveTo ("C :\\ test2.txt"); 62 newinfo = info. copyto ("C: \ test3.txt"); 63 readfileinfo (newinfo); 64} 65 finally 66 {67 If (info! = NULL) 68 info. Delete (); 69 If (newinfo! = NULL) 70 newinfo. Delete (); 71} 72}