copy a single entry from the archive

@param destDir
@param zf
@param ze
@throws IOException
325441
public void copyFileEntry(File destDir, ZipFile zf, ZipEntry ze) throws IOException {
        BufferedInputStream dis = new BufferedInputStream(zf.getInputStream(ze));
        try {
            copyFileEntry(destDir, ze.isDirectory(), ze.getName(), dis);
        } finally {
            try {
                dis.close();
            } catch (IOException ioe) {
            }
        }
    }
34713
private static function extract_zip( $zipfile, $dest ) {
		if ( ! class_exists( 'ZipArchive' ) ) {
			throw new \Exception( 'Extracting a zip file requires ZipArchive.' );
		}
		$zip = new ZipArchive();
		$res = $zip->open( $zipfile );
		if ( true === $res ) {
			$tempdir = implode(
				DIRECTORY_SEPARATOR,
				array(
					dirname( $zipfile ),
					Utils\basename( $zipfile, '.zip' ),
					$zip->getNameIndex( 0 ),
				)
			);

			$zip->extractTo( dirname( $tempdir ) );
			$zip->close();

			self::copy_overwrite_files( $tempdir, $dest );
			self::rmdir( dirname( $tempdir ) );
		} else {
			throw new \Exception( sprintf( "ZipArchive failed to unzip '%s': %s.", $zipfile, self::zip_error_msg( $res ) ) );
		}
	}
423510
public static function copyDirectory(string $source, string $dest)
    {
        if (!is_dir($dest)) {
            mkdir($dest, 0700, true);
        }
        if (is_dir($source) && ($dh = opendir($source))) {
            while (($file = readdir($dh)) !== false) {
                if ($file === '.' || $file === '..') {
                    continue;
                } elseif (is_dir("{$source}/{$file}")) {
                    self::copyDirectory("{$source}/{$file}", "{$dest}/{$file}");
                } else {
                    copy("{$source}/{$file}", "{$dest}/{$file}");
                }
            }
            closedir($dh);
        }
    }
592233
public static boolean copyFilesFromDirectoryToDirectory(File origDir,
															File destDir) {

		if (!origDir.exists()) {
			return false;
		}
		
		if (!destDir.exists()) {
			destDir.mkdirs();
		}
		
		File array[]=origDir.listFiles();
		if ( array!= null) {
			for (File file : array) {
				File destFile = new File(destDir, file.getName());
				if (file.isDirectory()) {
					copyFilesFromDirectoryToDirectory(file, destFile);
				} else {
					if (!copyFile(file, destFile)) {
						return false;
					}
				}
			}
		} else {
			return false;
		}

		return true;
	}
894959
public static void copyFile(@NotNull Path from, @NotNull Path to) throws IOException {
		Validate.isTrue(Files.exists(from), "%s is not exist or not a file", from);
		Validate.notNull(to);
		Validate.isTrue(!FileUtil.isDirExists(to), "%s is exist but it is a dir", to);
		Files.copy(from, to);
	}
95656
public static void unzip(InputStream in, File toDir) throws IOException {
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(in));
        try {
            ZipEntry entry = zis.getNextEntry();
            while (entry != null) {
                if (!entry.isDirectory()) {
                    String entryName = entry.getName();
                    File toFile = new File(toDir, entryName);
                    toFile.getParentFile().mkdirs();
                    OutputStream os = new FileOutputStream(toFile);
                    try {
                        try {
                            copy(zis, os);
                        } finally {
                            zis.closeEntry();
                        }
                    } finally {
                        closeQuietly(os);
                    }
                }
                entry = zis.getNextEntry();
            }
        } finally {
            closeQuietly(zis);
        }
    }
738441
public static void unZipFiles(InputStream inputStream, File outputFolder) throws IOException {
        ZipInputStream zis = new ZipInputStream(inputStream);
        ZipEntry ze = zis.getNextEntry();

        while (ze != null) {
            File file = new File(outputFolder, ze.getName());
            OutputStream os = new BufferedOutputStream(FileUtils.openOutputStream(file));

            try {
                IOUtils.copy(zis, os);
            } finally {
                IOUtils.closeQuietly(os);
            }

            zis.closeEntry();
            ze = zis.getNextEntry();
        }
    }
936674
private function __copyDir($src, $dst, &$files = null)
    {
        $dir = opendir($src);
        @mkdir($dst);
        while (false !== ($file = readdir($dir))) {
            if (('.' != $file) && ('..' != $file)) {
                if (is_dir($src.'/'.$file)) {
                    $this->__copyDir($src.'/'.$file, $dst.'/'.$file, $files);
                } else {
                    copy($src.'/'.$file, $dst.'/'.$file);
                    if (\is_array($files)) {
                        $files[] = $dst.'/'.$file;
                    }
                }
            }
        }
        closedir($dir);
    }
1196179
protected function copy($src, $dest)
    {
        if (!is_file($src) && !is_dir($src)) {
            return 'Source File or dir not found: ' . $src;
        }

        if (is_file($src)) {
            File::copy($src, $dest, true);
        } elseif (is_dir($src)) {
            Folder::copy($src, $dest, true);
        }

        return sprintf('Copy %s ===> %s', $src, $dest);
    }
541104
public static void unzip(InputStream is, File destDir)
            throws FileNotFoundException, IOException {
        BufferedOutputStream dest = null;
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is));
        ZipEntry entry;
        while ((entry = zis.getNextEntry()) != null) {
            //System.out.println("Extracting: " + entry);
            if (entry.isDirectory()) {
                // Otherwise, empty directories do not get created
                (new File(destDir, entry.getName())).mkdirs();
            } else {
                File f = new File(destDir, entry.getName());
                f.getParentFile().mkdirs();
                int count;
                byte data[] = new byte[BUFFER];
                // write the files to the disk
                FileOutputStream fos = new FileOutputStream(f);
                dest = new BufferedOutputStream(fos, BUFFER);
                while ((count = zis.read(data, 0, BUFFER)) != -1) {
                    dest.write(data, 0, count);
                }
                dest.flush();
                dest.close();
            }
        }
        zis.close();
    }
871121
private void unzipModuleData(File directory, File zipFile, boolean deleteZip) {
    try (InputStream in = new BufferedInputStream(new FileInputStream(zipFile)); ZipInputStream zin = new ZipInputStream(new BufferedInputStream(in))) {
      ZipEntry entry;
      while ((entry = zin.getNextEntry()) != null) {
        String entryName = entry.getName();
        if (!entryName.isEmpty()) {
          if (entry.isDirectory()) {
            File dir = new File(directory, entryName);
            if (!dir.exists()) {
              if (!new File(directory, entryName).mkdir()) {
                throw new PlatformManagerException("Failed to create directory");
              }
            }
          } else {
            int count;
            byte[] buffer = new byte[BUFFER_SIZE];
            BufferedOutputStream out = null;
            try {
              OutputStream os = new FileOutputStream(new File(directory, entryName));
              out = new BufferedOutputStream(os, BUFFER_SIZE);
              while ((count = zin.read(buffer, 0, BUFFER_SIZE)) != -1) {
                out.write(buffer, 0, count);
              }
              out.flush();
            } finally {
              if (out != null) {
                out.close();
              }
            }
          }
        }
      }
    } catch (Exception e) {
      throw new PlatformManagerException("Failed to unzip module", e);
    } finally {
      if (deleteZip) {
        zipFile.delete();
      }
    }
  }
789786
def copy_directory(src, dest, force=False):
    ''' 
    '''
    if os.path.exists(dest) and force is True:
        shutil.rmtree(dest)

    try:
        shutil.copytree(src, dest)
    except OSError as e:
        # If the error was caused because the source wasn't a directory
        if e.errno == errno.ENOTDIR:
            shutil.copy(src, dest)
        else:
            bot.error('Directory not copied. Error: %s' % e)
            sys.exit(1)
752196
public static void copyDir(File from, File to) throws FileNotFoundException, IOException {
        File[] files = from.listFiles();

        if (files != null) {
            for (File ff : files) {
                File tf = new File(to, ff.getName());
                if (ff.isDirectory()) {
                    if (tf.mkdir()) {
                        copyDir(ff, tf);
                    }
                } else if (ff.isFile()) {
                    copyFile(tf, ff);
                }
            }
        }
    }
1300314
public static function copyFile(string $source, string $dest)
    {
        $dir = dirname($dest);
        if (!is_dir($dir)) {
            mkdir($dir, 0700, true);
        }
        copy($source, $dest);
    }
1281079
public static void copyDirToDir(File source, File dest, FilenameFilter filter) throws IOException {
        if (!source.isDirectory() || !dest.isDirectory()) {
            return;
        }

        List<File> files = listFiles(source, filter, true);
        String sourcePath = source.getAbsolutePath();
        String destPath = dest.getAbsolutePath();
        for (File file : files) {
            String filePath = file.getAbsolutePath();
            if (sourcePath.equals(filePath)) {
                continue;
            }
            String newPath = destPath + File.separator + filePath.substring(sourcePath.length());
            File destFile = new File(newPath);
            if (file.isDirectory()) {
                destFile.mkdirs();
            } else {
                copy(file, destFile);
            }
        }
    }
1258324
public static void recursiveCopy(File original, File destDir) throws IOException {
        final String name = original.getName();
        final File destFile = new File(destDir, name);
        if (original.isDirectory()) {
            destFile.mkdir();
            for (File file : original.listFiles()) {
                recursiveCopy(file, destFile);
            }
        } else {
            final OutputStream os = new FileOutputStream(destFile);
            try {
                final InputStream is = new FileInputStream(original);
                copyStreamAndClose(is, os);
            } finally {
                // in case the input stream open fails
                safeClose(os);
            }
        }
    }
597721
public static function copy($src, $dest, $force = false)
	{
		// Check src path
		if (!is_readable($src))
		{
			throw new \UnexpectedValueException(__METHOD__ . ': Cannot find or read file: ' . $src);
		}

		// Check folder exists
		$dir = dirname($dest);

		if (!is_dir($dir))
		{
			Dir::create($dir);
		}

		// Check is a folder or file
		if (file_exists($dest))
		{
			if ($force)
			{
				FileHelper::delete($dest);
			}
			else
			{
				throw new Exception($dest . ' has exists, copy faieed.');
			}
		}

		if (!@ copy($src, $dest))
		{
			throw new Exception(__METHOD__ . ': Copy failed.');
		}

		return true;
	}