Copy all files in a directory

xiaoxiao2021-03-06  46

Class app

{

///

/// Copy all files for the specified directory, do not include subdirectory

///

/// Original directory

/// Target directory

/// If true, it means that the same name file is overwritten, otherwise it is not overwritten

Public Static Void CopyFiles (String Sourcedir, String Targetdir, Bool Overwrite)

{

CopyFiles (Sourcedir, Targetdir, Overwrite, False);

}

///

/// Copy all files for the specified directory

///

/// Original directory

/// Target directory

/// If true, override the same name file, otherwise it is not overwriting

/// If true, contains the directory, otherwise it does not include

Public Static Void CopyFiles (String Sourcedir, String Targetdir, Bool Overwrite, Bool CopyDir)

{

String [] FileEntries = Directory.getFiles (SOURCEDIR);

IF (OVERWRITE)

{

FOREACH (String Filename In Filentries)

{

File.copy (filename, targetdir filename.substring (filename.lastindexof ("//")), true);

//Console.writeline (FileName "--> " Targetdir FileName.Substring (FileName.lastIndexOf ("//"))));

}

}

Else

{

FOREACH (String Filename In Filentries)

{

IF (! file.exists (targetdir filename.substring (filename.lastindexof ("//")))))))))))

{

File.copy (FileName, Targetdir filename.substring (filename.lastindexof ("//"))));

//Console.writeline (FileName "--> " Targetdir FileName.Substring (FileName.lastIndexOf ("//"))));

}

}

}

IF (CopyDir)

{

FOREACH (String Subdir in Directory.GetDirector)

{

String newsubdir = targetdir subdir.substring (Subdir.lastIndexof ("//")); if (! Directory.exists (newsubdir))

Directory.createdIRectory (newsubdir);

CopyFiles (Subdir, NewSubdir, OverWrite, CopyDir);

}

}

}

}

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

New Post(0)