Specify all content below the folder COPY below the target folder

xiaoxiao2021-03-06  19

/ / =========================================================================================================================================================================================== ======

/ / Implement a static method to copy all the contents below the specified folder below to the target folder

/ / =========================================================================================================================================================================================== ======

Public Static Void Copydir (String Srcpath)

{

/ / Check if the target directory ends with directory segmentation characters if not added

IF (aimpath [aimpath.length-1]! = path.directoryseparatorchar)

Aimpath = path.directoryseparatorchar;

/ / Judgment if the target directory exists if there is no existence, new

IF (! Directory.exists (aimpath)) Directory.createdIRectory (AIMPATH);

/ / Get a list of files of the source, which is an array containing files and directory paths.

// If you point to the file under the COPY target file without including a directory, please use the following method

// String [] filelist = Directory.getFiles (srcpath);

String [] filelist = Directory.GetFileSystemEntries (srcpath);

// Traverse all files and directories

FOREACH (String File in filelist)

{

// Before the directory processing, if there is this directory, recursively copy the file below this directory.

IF (Directory.exists (file))

CopyDir (File, Aimpath path.getFileName (file));

/ / Otherwise directly copy file

Else

File.copy (File, Aimpath Path.GetFileName (file), true);

}

}

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

New Post(0)