Skip to content

qie.moveFile

Signature: qie.moveFile(file, destination, shouldCreatePath*)

Returns: String destinationFileName - the file name and extension of the destination file (in case it is renamed to avoid overwriting an existing file)

Move a file to destination.

Parameters

Type Name Description Default
String, File, or NetFile file the file to move. This can be either a string representing the file's full path and file name (i.e. 'c:\\temp\\file.txt'), a java.io.File object or a com.qvera.qie.utils.NetFile object.
String, File, or NetFile destination the path to move the file to. This is either a folder (i.e. c:\\temp) or a file (i.e. c:\\temp\\file.txt) and can be specified using a string, a java.io.File object or a com.qvera.qie.utils.NetFile object.
Boolean shouldCreatePath* (optional) true, to create the path where the file is being moved if it doesn't exist; false, otherwise false

Example

// Move file examples:
// Example: file as String path, destination as String path
qie.writeFile("/tmp/mine.txt", "Sample text.", true);
var movedFileName = qie.moveFile(
    "/tmp/mine.txt",                       // source file location as String
    "/tmp/otherplace/mineOtherFile.txt",   // destination file location as String
    true                                   // should create path
);


// Example: file as File, destination as File
var sourceFileObject = qie.newFile("/tmp/mine-file.txt");
qie.writeFile(sourceFileObject, "Sample text written using a File object.", true);

var destinationFileObject = qie.newFile("/tmp/otherplace/mine-file-moved.txt");
var movedFileNameWithFiles = qie.moveFile(
    sourceFileObject,       // source java.io.File object
    destinationFileObject,  // destination java.io.File object
    true                    // should create path
);


// Example: file as String path, destination as File
qie.writeFile("/tmp/mine-mixed1.txt", "Sample text.", true);
var movedFileNameFromStringToFile = qie.moveFile(
    "/tmp/mine-mixed1.txt",                               // source file location as String
    qie.newFile("/tmp/otherplace/mine-mixed1-moved.txt"), // dest file location as java.io.File
    true                                                  // should create path
);


// Example: file as File, destination as String path
var mixedSourceFileObject = qie.newFile("/tmp/mine-mixed2.txt");
qie.writeFile(mixedSourceFileObject, "Sample text for mixed example.", true);

var movedFileNameFromFileToString = qie.moveFile(
    mixedSourceFileObject,                   // source java.io.File 
    "/tmp/otherplace/mine-mixed2-moved.txt", // dest file location as String
    true                                     // should create path
);