package alogorithm;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
public class CopyFile {
public static void main(String[] args) throws IOException
{
copyDir("C:\\DATAPART4", "C:\\Data");
}
public static void copyDir(String oldPath,String newPath) throws IOException{
File file = new File(oldPath);
String[] filePath = file.list();
if (!(new File(newPath)).exists()) {
(new File(newPath)).mkdir();
}
for (int i = 0; i < filePath.length; i++) {
if ((new File(oldPath + File.separator + filePath[i])).isDirectory()) {
copyDir(oldPath + File.separator + filePath[i], newPath + File.separator + filePath[i]);
}
if (new File(oldPath + File.separator + filePath[i]).isFile()) {
File source = new File(oldPath + File.separator + filePath[i]);
File dest = new File(newPath + File.separator + filePath[i]);
if(!(dest.exists()))
{
Files.copy(source.toPath(), dest.toPath());
}
}
}
}
}