MoveFile(src$, dst$[, t])
MoveFile(src$, dst$[, func, userdata])
src$
to the
file or directory specified in dst$
. Note that dst$
must not exist
or MoveFile()
will fail. Also, src$
must not be a volume's root
directory because this obviously cannot be moved anywhere.
Moving files (or directories) on the same volume is really quick and
takes almost no time. When moving files from one volume to another,
MoveFile()
first has to copy the files and in a second step, delete
them from the original volume. This process is much slower than moving
files around on the same volume. That is why you can specify a callback
function which monitors the progress of this operation.
MoveFile()
supports several optional arguments. Before Hollywood 9.0, those
had to be passed as optional parameters (see above). Since Hollywood 9.0,
however, it is recommended to use the new syntax, which has a single optional
table argument that can be used to pass one or more optional arguments to
MoveFile()
.
The following table fields are recognized by this function:
Force:
True
, write- or delete-protected files will automatically be deleted
without asking the callback function first. Note that if there is no callback function
and Force
is set to False
(the default), MoveFile()
will just skip all write- or delete-protected
files instead of deleting them. Note that Force
is only used when MoveFile()
actually needs to
delete files, i.e. when moving files from one volume to another. Moving files on the same
volume doesn't involve any deleting. Defaults to False
. (V9.0)
BufferSize:
BufferSize
is only used when MoveFile()
actually needs to
copy files, i.e. when moving files from one volume to another. Moving
files on the same volume doesn't involve copying. (V9.0)
FailOnError:
MoveFile()
will fail if a file or directory can't be copied or deleted. You can change
this behaviour by setting FailOnError
to False
. In that case, MoveFile()
won't fail if a
file or directory can't be copied or deleted but instead your callback function, if there is one, will
be notified using the #MOVEFILE_COPYFAILED
and #MOVEFILE_DELETEFAILED
messages and your callback must
tell MoveFile()
how to proceed (retry, continue, abort). See below to learn how to set up a callback
function for MoveFile()
. Note that FailOnError
is only used when MoveFile()
actually needs to
copy and delete files, i.e. when moving files from one volume to another. Moving files on the same
volume doesn't involve any copying or deleting. FailOnError
defaults to True
. (V9.0)
Async:
True
, MoveFile()
will operate in asynchronous mode. This means that
it will return immediately, passing an asynchronous operation handle to you. You can then
use this asynchronous operation handle to finish the operation by repeatedly calling
ContinueAsyncOperation() until it returns True
. This is
very useful in case your script needs to do something else while the operation is in progress,
e.g. displaying a status animation or something similar. By putting MoveFile()
into asynchronous
mode, it is easily possible for your script to do something else while the operation is
being processed. See ContinueAsyncOperation for details. Defaults to False
. (V9.0)
Adapter:
UserTags:
Callback:
MoveFile()
will call it from time to time
so that you can update a progress bar. It will also be called when a file is delete-protected
to ask you how to proceed. If there is no callback function, MoveFile()
will silently skip delete-protected
files. The callback function receives one argument: A table that contains
more information.
Note that the callback function will only be called when moving files across volumes. Moving files on the same volume can be done instantly and won't result in any callback invocation. Also note that if files are moved across volumes and you do not specify a callback function, files that are delete-protected won't be deleted but will just be copied to the new location without deleting the old file.
The following callback types are available:
#MOVEFILE_UNPROTECT:
#MOVEFILE_UNPROTECT
will be called when MoveFile()
needs to delete a file which is delete-protected. The parameter table for
this callback type will contain the following fields:
Action:
#MOVEFILE_UNPROTECT
File:
UserData:
UserData
table field (see below).
This callback function needs to return True
if it is okay to unprotect
the file or False
if it shall not be unprotected. If you return -1,
the move operation will be completely aborted.
#MOVEFILE_DELETE:
#MOVEFILE_DELETE
should normally return False
. If it returns True
,
MoveFile()
will abort the entire operation.
Action:
#MOVEFILE_DELETE
File:
UserData:
UserData
table field (see below).
#MOVEFILE_COPY:
MoveFile()
is copying files. The callback function
of type #MOVEFILE_COPY
should normally return False
. If it returns True
, MoveFile()
will abort the entire operation.
Action:
#MOVEFILE_COPY
Source:
Destination:
Copied:
Filesize:
UserData:
UserData
table field (see below).
#MOVEFILE_DELETEFAILED:
FailOnError
tag has been set to False
(see above).
In that case, the callback function of type #MOVEFILE_DELETEFAILED
will be called whenever a
delete operation has failed. It has to return True
to abort the entire operation, False
to
continue even though an error has occurred or -1 to retry the delete operation that has
just failed. The following fields will be set in the table parameter that is passed to your
callback function:
Action:
#MOVEFILE_DELETEFAILED
File:
UserData:
UserData
table field (see below).
(V9.0)
#MOVEFILE_COPYFAILED:
FailOnError
tag has been set to False
(see above).
In that case, the callback function of type #MOVEFILE_COPYFAILED
will be called whenever a
copy operation has failed. It has to return True
to abort the entire operation, False
to
continue even though an error has occurred or -1 to retry the copy operation that has
just failed. The following fields will be set in the table parameter that is passed to your
callback function:
Action:
#MOVEFILE_COPYFAILED
Source:
Destination:
UserData:
UserData
table field (see below).
(V9.0)
UserData:
UserData
tag you can easily pass data to your callback function.
You can specify a value of any type in UserData
. Numbers, strings, tables, and
even functions can be passed as user data. Your callback will receive this
data in the UserData
field in the table that is passed to it.
MoveFile("image.png", "images/image.png")Moves the file "image.png" to the subdirectory "images" while keeping its name.