File and folder operations:
C/s:winform can manipulate client files
B/s:brower Server
Namespaces: Using System. IO;
1. File class:
Create: File.create (path); Create file, return FileStream
FileStream fs = file.create (path), after which it needs to be closed or not open, fs.close ();
Delete: File.delete (path); no return value
Copy files: file.copy (source file, target file);
Cut files: File.move (source file path, target path);
Determine if the file exists: file.exists (path); return Boolean, true means existing
File encryption: File.encrypt (); File.decrypt (); decrypt
File.getcreationtime (path); Get creation time, return datetime type Setcreationtime (path, datetime type); Modify creation time
File.getlastaccesstime (path); Last access time, return datetime type Setlastaccesstime (path, datetime type); Modify access time
File.getlastwritetime (path); Last modified time, return datetime type Setlastwritetime (path, datetime type); Modify modification Time
2. Directory classes, directories (folders)
Directory. CreateDirectory (path); Create directory
Directory. Delete (path); Remove directory
Directory. Exists (path), whether the directory exists
Three-time get and set
Directory. GetDirectories (path); Gets a subdirectory that returns a string array
Directory. GetFiles (path); Get Child Files! Name! , returns a string array, string[] s = Directory. GetFiles (path);
Directory. Getdirectoryroot (path); Get root directory
Directory. GetParent (path); Get Top level Directory
------------------------------------------------------------------------------------------------------
FileInfo class
Is the instance method, need to create object new to use, above is the static method of file
Create file: FileInfo f = new FileInfo (path); FileStream s = f.create (); S.close ();
Delete file: FileInfo f = new FileInfo (path); F.delete ();
Copy file: FileInfo f = new FileInfo (path), F.copyto (target path, whether overwrite (true is overwrite));
Move file: FileInfo f = new FileInfo (path); F.moveto (target path);
File exists: FileInfo f = new FileInfo (path); bool B = f.exists; Boolean, is a property
Get file name: FileInfo f = new FileInfo (path); string s = F.fullname; property, file name with path
Get creation time: DateTime d = f.creationtime, three time is the same, all attributes
Set creation time: F. CreationTime = DateTime.Now.AddDays (100); All three of them are the same.
Get file size: F. Length
DirectoryInfo class
Create directory: DirectoryInfo d = new DirectoryInfo (path); D.create ();
Delete directory: D. Delete ();
Move directory: D. MoveTo (target path);
Whether the directory exists: bool B = d.exists;
Get directory full name: D. FullName;
Get the Sub file! Object Information! : fileinfo[] f = d.getfiles (); Returns an array of file objects, the contents of which are more detailed, D.getfiles ("*.exe") only get EXE files
Get subdirectory: directoryinfo[] dr = D.getdirectories ();
File and folder operations