I am trying to use the Apache Common's FileUtil to use CopyDirectory to transfer files onto other disks. I am however getting an error when it comes to transfering My Documents. Also, I don't know why, but when I select a specific path like C:\Users[UserName]\Documents it doesn't give me JUST the contents in Documents it gives me a few other folders in the User's Folder... I don't know why this is. I also IOException when I run CopyDirectory on MyDocuments... when it's trying to copy MyMusic (which I don't know why it's doing that in the first place.
In my code it copies Favorites and Desktop decently... though it seems to have changed the folder in Favorites "Favorites Toolbar" to "Links" folder.
Any help would be great. Thanks!
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.commons.io.*;
public class TransferJet {
public static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
public static void main(String[] args) throws IOException {
System.out.print("Please enter the username:");
String user = in.readLine();
System.out.print("Please enter the drive letter of the old primary partition:");
String oldPrimaryLetter = in.readLine();
System.out.print("Please enter the drive letter of the old secondary partition:");
String oldSecondaryLetter = in.readLine();
System.out.print("Please enter the drive letter of the new primary partition:");
String newPrimaryLetter = in.readLine();
System.out.print("Please enter the driver letter of the new secondary partition:");
String newSecondaryLetter = in.readLine();
if(user.equals("") || oldSecondaryLetter.equals("") || oldPrimaryLetter.equals("") || newPrimaryLetter.equals("") || newSecondaryLetter.equals(""))
{
System.out.println("Invalid directory or file name.");
System.exit(0);
}
String newFiles = "";
String oldFiles = "";
File source = null;
File destination = null;
System.out.println("Moving Favorites...");
oldFiles = oldPrimaryLetter + ":\\Users\\" + user + "\\Favorites";
//String oldFilesA = "C:\\Users\\ashih\\Favorites";
//String newFilesA = "G:\\Users\\ashih\\Favorites";
newFiles = newPrimaryLetter + ":\\Users\\" + user + "\\Favorites";
source = new File(oldFiles);
destination = new File(newFiles);
FileUtils.copyDirectory(source, destination);
System.out.println("Moving Desktop...");
oldFiles = oldPrimaryLetter + ":\\Users\\" + user + "\\Desktop";
newFiles = newPrimaryLetter + ":\\Users\\" + user + "\\Desktop";
source = new File(oldFiles);
destination = new File(newFiles);
FileUtils.copyDirectory(source, destination);
System.out.println("Moving My Documents...");
oldFiles = oldPrimaryLetter + ":\\Users\\" + user + "\\";
newFiles = newPrimaryLetter + ":\\Users\\" + user + "\\Documents";
source = new File(oldFiles);
destination = new File(newFiles);
FileUtils.copyDirectory(source, destination);
System.out.println("Moving Old Secondary to New Secondary...");
oldFiles = oldSecondaryLetter + ":\\";
newFiles = newSecondaryLetter + ":\\";
source = new File(oldFiles);
destination = new File(newFiles);
FileUtils.copyDirectory(source, destination);
}
}