Android - Copy Files (all at the same time)
===

I am currently working on a basic file browser for android. I have a working version for copying files, however as it works its way through directories it copies the files it finds. I want to change that so that I can find the total size of all files before starting to copy, as to help with a better progress bar.

If there is another way to find the total size of a directory and all its contents?

Here is my current version. I am having trouble changing this, I have tried using an arrayList however when I try to copy the files at the end, I think they are trying to copy in the wrong order.

    public void copyDirectory(File sourceLocation , File targetLocation) throws IOException {
	        if (sourceLocation.isDirectory()) {
	            if (!targetLocation.exists() && !targetLocation.mkdirs()) {
	                throw new IOException("Cannot create directory: " + targetLocation.getAbsolutePath());
	            }

	            String[] children = sourceLocation.list();
	            for (int i = 0; i < children.length; i++) {
	                copyDirectory(new File(sourceLocation, children[i]),
	                        new File(targetLocation, children[i]));
	            }
	        } else {	        	
	            File directory = targetLocation.getParentFile();
	            if (directory != null && !directory.exists() && !directory.mkdirs()) {
	                throw new IOException("Cannot create directory: " + directory.getAbsolutePath());
	            }

	            FileInputStream in = new FileInputStream(sourceLocation);
	            FileOutputStream out = new FileOutputStream(targetLocation);

	            long fileLength = sourceLocation.length();
	            
	            byte[] buf = new byte[1024];
	            long total = 0;
	            int len;
	            while ((len = in.read(buf)) > 0) {
	                out.write(buf, 0, len);
	                total += len;
	                publishProgress((int) (total * 100 / fileLength));
	            }
	            in.close();
	            out.close();
	        }
	    }