AntDeployAgent/Util/CopyHelper.cs
/// <summary>
/// copies if the files and folders are existent in referenced directory
/// </summary>
/// <param name="srcDir">source directory</param>
/// <param name="dstDir">destination directory</param>
/// <param name="refDir">reference directory</param>
/// <param name="copySubDirs">copy sub directories</param>
copies if the files and folders are existent in referenced directory
copies if the files and folders are existent in referenced directory
public static void DirectoryCopyWithRef(string srcDir, string dstDir, string refDir, bool copySubDirs)
        {
            DirectoryInfo dir = new DirectoryInfo(refDir);
            if (!dir.Exists)
                throw new DirectoryNotFoundException("Reference directory does not exist or could not be found: " + refDir);
            if (!Directory.Exists(dstDir))
                Directory.CreateDirectory(dstDir);
            FileInfo[] files = dir.GetFiles();
            foreach (FileInfo file in files)
            {
                string srcFile = Path.Combine(srcDir, file.Name);
                string dstFile = Path.Combine(dstDir, file.Name);
                if (File.Exists(srcFile))
                {
                    File.Copy(srcFile, dstFile, true);
                }
            }
            if (copySubDirs)
            {
                DirectoryInfo[] subDirs = dir.GetDirectories();
                foreach (DirectoryInfo subDir in subDirs)
                {
                    string srcDirSub = Path.Combine(srcDir, subDir.Name);
                    string dstDirSub = Path.Combine(dstDir, subDir.Name);
                    DirectoryCopyWithRef(srcDirSub, dstDirSub, subDir.FullName, true);
                }
            }
        }
public static void DirectoryCopyWithRef ( string srcDir , string dstDir , string refDir , bool copySubDirs ) { DirectoryInfo dir = new DirectoryInfo ( refDir ) ; if ( ! dir . Exists ) throw new DirectoryNotFoundException ( " " + refDir ) ; if ( ! Directory . Exists ( dstDir ) ) Directory . CreateDirectory ( dstDir ) ; FileInfo [ ] files = dir . GetFiles ( ) ; foreach ( FileInfo file in files ) { string srcFile = Path . Combine ( srcDir , file . Name ) ; string dstFile = Path . Combine ( dstDir , file . Name ) ; if ( File . Exists ( srcFile ) ) { File . Copy ( srcFile , dstFile , true ) ; } } if ( copySubDirs ) { DirectoryInfo [ ] subDirs = dir . GetDirectories ( ) ; foreach ( DirectoryInfo subDir in subDirs ) { string srcDirSub = Path . Combine ( srcDir , subDir . Name ) ; string dstDirSub = Path . Combine ( dstDir , subDir . Name ) ; DirectoryCopyWithRef ( srcDirSub , dstDirSub , subDir . FullName , true ) ; } } }
copies if the files and folders are existent in referenced directory
copies if the files and folders are existent in referenced directory
srcDir
string
None
dstDir
string
None
refDir
string
None
copySubDirs
bool
copy sub directories
copy sub directories