copy all all files and folders from a directory to another ubuntu command code example

Example 1: get all files within multiple directories python

from pathlib import Path
for f in Path().cwd().glob("../*.ext"):
    print(f)
    # do other stuff

Example 2: java copy file from one directory to another efficiently

private static void copyFileUsingStream(File source, File dest) throws IOException {
    InputStream is = null;
    OutputStream os = null;
    try {
        is = new FileInputStream(source);
        os = new FileOutputStream(dest);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = is.read(buffer)) > 0) {
            os.write(buffer, 0, length);
        }
    } finally {
        is.close();
        os.close();
    }
}

Tags: