Copy a file.

        Copy a file from elsewhere in Canvas into a folder.
        
        Copying a file across contexts (between courses and users) is permitted,
        but the source and destination must belong to the same institution.
184555
def copy_file(self, dest_folder_id, source_file_id, on_duplicate=None):
        
        path = {}
        data = {}
        params = {}

        # REQUIRED - PATH - dest_folder_id
        """ID"""
        path["dest_folder_id"] = dest_folder_id

        # REQUIRED - source_file_id
        """The id of the source file"""
        data["source_file_id"] = source_file_id

        # OPTIONAL - on_duplicate
        """What to do if a file with the same name already exists at the destination.
        If such a file exists and this parameter is not given, the call will fail.
        
        "overwrite":: Replace an existing file with the same name
        "rename":: Add a qualifier to make the new filename unique"""
        if on_duplicate is not None:
            self._validate_enum(on_duplicate, ["overwrite", "rename"])
            data["on_duplicate"] = on_duplicate

        self.logger.debug("POST /api/v1/folders/{dest_folder_id}/copy_file with query params: {params} and form data: {data}".format(params=params, data=data, **path))
        return self.generic_request("POST", "/api/v1/folders/{dest_folder_id}/copy_file".format(**path), data=data, params=params, single_item=True)
547211
public static boolean copy(File src,
                             FileSystem dstFS, Path dst,
                             boolean deleteSource,
                             Configuration conf) throws IOException {
    dst = checkDest(src.getName(), dstFS, dst, false);

    if (src.isDirectory()) {
      if (!dstFS.mkdirs(dst)) {
        return false;
      }
      File contents[] = src.listFiles();
      for (int i = 0; i < contents.length; i++) {
        copy(contents[i], dstFS, new Path(dst, contents[i].getName()),
             deleteSource, conf);
      }
    } else if (src.isFile()) {
      InputStream in = null;
      OutputStream out =null;
      try {
        in = new FileInputStream(src);
        out = dstFS.create(dst);
        IOUtils.copyBytes(in, out, conf);
      } catch (IOException e) {
        IOUtils.closeStream( out );
        IOUtils.closeStream( in );
        throw e;
      }
    } else {
      throw new IOException(src.toString() + 
                            ": No such file or directory");
    }
    if (deleteSource) {
      return FileUtil.fullyDelete(src);
    } else {
      return true;
    }
  }
48208
public static <E extends Exception> void copy(File srcFile, File destDir, final boolean preserveFileDate,
            final Try.BiPredicate<? super File, ? super File, E> filter) throws UncheckedIOException, E {
        if (!srcFile.exists()) {
            throw new IllegalArgumentException("The source file doesn't exist: " + srcFile.getAbsolutePath());
        }

        if (destDir.exists()) {
            if (destDir.isFile()) {
                throw new IllegalArgumentException("The destination file must be directory: " + destDir.getAbsolutePath());
            }
        } else {
            if (!destDir.mkdirs()) {
                throw new UncheckedIOException(new IOException("Failed to create destination directory: " + destDir.getAbsolutePath()));
            }
        }

        if (destDir.canWrite() == false) {
            throw new UncheckedIOException(new IOException("Destination '" + destDir + "' cannot be written to"));
        }

        String destCanonicalPath = null;
        String srcCanonicalPath = null;
        try {
            srcFile = srcFile.getCanonicalFile();
            destDir = destDir.getCanonicalFile();
            destCanonicalPath = destDir.getCanonicalPath();
            srcCanonicalPath = srcFile.getCanonicalPath();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }

        if (srcFile.isDirectory()) {
            if (destCanonicalPath.startsWith(srcCanonicalPath) && (destCanonicalPath.length() == srcCanonicalPath.length()
                    || destCanonicalPath.charAt(srcCanonicalPath.length()) == '/' || destCanonicalPath.charAt(srcCanonicalPath.length()) == '\\')) {
                throw new IllegalArgumentException(
                        "Failed to copy due to the target directory: " + destCanonicalPath + " is in or same as the source directory: " + srcCanonicalPath);
            }

            try {
                doCopyDirectory(srcFile, destDir, preserveFileDate, filter);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        } else {
            File destFile = null;

            try {
                if (destDir.getCanonicalPath().equals(srcFile.getParentFile().getCanonicalPath())) {
                    destFile = new File(destDir, "Copy of " + srcFile.getName());
                } else {
                    destFile = new File(destDir, srcFile.getName());
                }
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }

            doCopyFile(srcFile, destFile, preserveFileDate);
        }
    }
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);
	}
1265457
def copy_files(source_files, target_directory, source_directory=None):
    """"""
    try:
        os.makedirs(target_directory)
    except:     # TODO: specific exception?
        pass
    for f in source_files:
        source = os.path.join(source_directory, f) if source_directory else f
        target = os.path.join(target_directory, f)
        shutil.copy2(source, target)
486213
def copy_file_from_agent(
        host,
        remote_path,
        file_path='.',
        username=None,
        key_path=None
):
    

    return copy_file(host, file_path, remote_path, username, key_path, 'get')
1054073
function copyFiles(srcfile, dstfile, callback) {
        var fs = require("fs");
        var rs = fs.createReadStream(srcfile);
        var ws = fs.createWriteStream(dstfile);
        rs.on("data", function(d) {
            ws.write(d);
        });
        rs.on("end", function() {
            ws.end();
            callback(true);
        });
    }
1229604
def copy_file(self, filepath):
        
        copy_file = False
        try:
            copy_file = self.data[filepath]['copy']
        except KeyError:
            return False
        return copy_file
474729
private static void copyFile(File in, File out) throws IOException {
        try (FileInputStream inStream = new FileInputStream(in);
                FileOutputStream outStream = new FileOutputStream(out);) {
            FileChannel inChannel = inStream.getChannel();
            inChannel.transferTo(0, inChannel.size(), outStream.getChannel());
        }
    }
237544
def copy(options)
      destination = copy_destination options
      to_path = join_paths @root_dir, destination
      to_path_exists = File.exist? to_path

      preserve_existing = false? options[:overwrite]

      copy_resource_to_path to_path, preserve_existing
      copy_pstore_to_path to_path, preserve_existing

      to_path_exists
    end
498453
def _copy_files(source, target):
    
    source_files = listdir(source)
    if not exists(target):
        makedirs(target)
    for filename in source_files:
        full_filename = join(source, filename)
        if isfile(full_filename):
            shutil.copy(full_filename, target)
722252
def copy(location):
	""""""
	copyData = settings.getDataFile()
	copyFileLocation = os.path.abspath(location)
	copy = {"copyLocation": copyFileLocation}
	dataFile = open(copyData, "wb")
	pickle.dump(copy, dataFile)
	speech.speak(location + " copied successfully!")
	speech.speak("Tip: use 'hallie paste' to paste this file.")
50415
def copy_files!
        destination = temp_transformed_path

        if has_base?
          FileUtils.cp_r("#{base_spec.temp_raw_path}/.", destination)
        end

        begin
          FileUtils.cp_r("#{before_path}/.", destination)
        rescue Errno::ENOENT => e
          raise e unless has_base?
        end
      end
97041
def copy_to_scratch(file_mapping, dry_run=True):
        
        for key, value in file_mapping.items():
            if not os.path.exists(key):
                continue
            if dry_run:
                print ("copy %s %s" % (key, value))
            else:
                print ("copy %s %s" % (key, value))
                copyfile(key, value)

        return file_mapping
246644
function copyFile(from, to) {
  return new Promise((resolve, reject) => {
    fs.copyFile(from, to, (err) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(to);
    });
  });
}
688527
def copy_file(self, from_path, to_path, replace=False):
        
        f = self.get_file(from_path)
        if f.copy(to_path, replace):
            self.set_cache_buster(to_path, f.hash())
1262887
def do_copy(self, line):
        '''
        
        '''
        words = line.split()
        source, destination = words
        destination_repo = self._get_destination_repo(destination)
        local_file_source = ':' not in source

        if local_file_source:
            destination_repo.upload_packages([source])
        else:
            source_repo_name, _, package_spec = source.partition(':')
            try:
                source_repo = self.network.get_repo(source_repo_name)
            except UnknownRepoError:
                raise ShellError(
                    'Unknown repository {}'.format(source_repo_name)
                )

            # copy between repos with the help of temporary storage
            try:
                source_repo.download_packages(package_spec, self.__temp_dir)
                destination_repo.upload_packages(self.__temp_dir.files)
            finally:
                self.__temp_dir.clear()