import java.io.File; import java.util.*; public class DirectoryStructureCopy{ private String source; private String target; public DirectoryStructureCopy(String source, String target){ this.source = source; this.target = target; } public List<File> getDirectory(File sourceFile){ List<File> result = new ArrayList<File>(); //System.out.println(sourceFile.getPath()+" is Directory :"+ sourceFile.isDirectory()); if(sourceFile.isDirectory()){ File[] dirFiles = sourceFile.listFiles(); for(int i=0; i < dirFiles.length; i++){ if(dirFiles[i].isDirectory()){ result.add(dirFiles[i]); result.addAll(getDirectory(dirFiles[i])); } } } return result; } public void copyFile(List<File> sourceDirectory, File targetDirectory, String sourceURL){ if(targetDirectory.isDirectory()){ for(File file:sourceDirectory){ String path = file.getAbsolutePath(); path = path.replace(sourceURL, targetDirectory.getAbsolutePath()); File newFile = new File(path); if((newFile.exists() && newFile.isFile()) || !newFile.exists()){ newFile.mkdir(); } } } } public void directoryCopy(){ List<File> copyLists= getDirectory(new File(this.source)); System.out.println("find Directory:"); for(File file: copyLists){ System.out.println(file.getAbsolutePath()); } copyFile(copyLists,new File(this.target), this.source); } public static void main(String [] args){ String sourceURL = args[0]; String targetURL = args[1]; DirectoryStructureCopy copyObj = new DirectoryStructureCopy(sourceURL, targetURL); copyObj.directoryCopy(); } }