copy
Description:
Copies the file this to the location specified by destination
.
Can not handle recursive copies of directories.
If the flag g_file_copy_overwrite is specified an already existing destination
file is
overwritten.
If the flag g_file_copy_nofollow_symlinks is specified then symlinks will be copied as symlinks, otherwise the target of the this symlink will be copied.
If the flag g_file_copy_all_metadata is specified then all the metadata that is possible to copy is copied, not just the default subset (which, for instance, does not include the owner, see FileInfo ).
If cancellable
is not null, then the operation can be cancelled by triggering the cancellable
object from another thread. If the operation was cancelled, the error g_io_error_cancelled will be returned.
If progress_callback
is not null, then the operation can be monitored by setting this to a
FileProgressCallback function. progress_callback_data
will
be passed to this function. It is guaranteed that this callback will be called after all data has been transferred with the total number of
bytes copied during the operation.
If the this file does not exist, then the g_io_error_not_found error is
returned, independent on the status of the destination
.
If g_file_copy_overwrite is not specified and the target exists, then the error g_io_error_exists is returned.
If trying to overwrite a file over a directory, the g_io_error_is_directory error is returned. If trying to overwrite a directory with a directory the g_io_error_would_merge error is returned.
If the source is a directory and the target does not exist, or g_file_copy_overwrite is specified and the target is a file, then the g_io_error_would_recurse error is returned.
If you are interested in copying the File object itself (not the on-disk file), see dup.
Example: Copy a file, sync:
public static int main (string[] args) {
// Copy my-test-1.txt to my-test-2.txt:
File file1 = File.new_for_path ("my-test-1.txt");
File file2 = File.new_for_path ("my-test-2.txt");
try {
file1.copy (file2, 0, null, (current_num_bytes, total_num_bytes) => {
// Report copy-status:
print ("%" + int64.FORMAT + " bytes of %" + int64.FORMAT + " bytes copied.\n",
current_num_bytes, total_num_bytes);
});
} catch (Error e) {
print ("Error: %s\n", e.message);
}
return 0;
}
valac --pkg gio-2.0 GLib.File.copy.vala
Parameters:
this |
input File |
destination |
destination File |
flags |
set of FileCopyFlags |
cancellable |
optional Cancellable object, null to ignore |
progress_callback |
function to callback with progress information, or null if progress information is not needed |
progress_callback_data |
user data to pass to |
Returns:
true on success, false otherwise. |