Copy the folder all content and 2 functions of the entire folder (original)

xiaoxiao2021-03-05  51

/ / =========================================================================================================================================================================================== ====== // Implement a static method to copy all content below the specified folder below // // If the target folder is read-only attribute, it will report an error. // april 18april2005 in stu // =========================================== ============ Public static void copydir (string srcpath, string aimpath) {Try {// Check whether the target directory ends if the directory split character is not added IF (Aimpath [aimpath.length- 1]! = Path.directoryseParatorChar) AIMPATH = path.directoryseParatorChar; / / Determine if the target directory exists if there is no new IF (! Directory.exists (Aimpath)) Directory.createdIRectory (AIMPATH); // Get source directory A list of files, which is an array containing files and directory paths // If you point to the file below the COPY target file without including a directory, use the following method // String [] filelist = Directory.GetFiles (srcpath); string [] filelist = directory.getFileSystem; // Traverse all files and directories ForEach (String file in file in file in file) {// first as directory processing If there is this directory, recursive Copy this directory below the file IF (Directory. EXISTS (File) COPYDIR (File, Aimpath Path.GetFileName (file)); / / Otherwise directly Copy file else file.copy (file, aimpath path.getFileName (file), true);}} catch (Exception E ) {MessageBox.show (e.tostring ());}}

转载请注明原文地址:https://www.9cbs.com/read-34598.html

New Post(0)