movefile()

Read(5542) Label: file, move, delete, rename,

Here’s how to use movefile() function.

movefile( fn:z,path )

Description:

Move, delete, or rename a file.

Syntax:

movefile(fn:z,path)

Note:

The function moves file fn to a file specified by parameter path. Delete file fn if path is absent; rename the file if only the file name is specified in the path.

Parameter:

fn

File name

z

An integer; it represents the zone table number when parameter fn is a homo-name files group; or is omitted when fn isn’t a homo-name files group

path

The path (with file name) along which the file is moved, or a file name

Option:

@y

Force an execution of the function if the target file already exists. Without the option you can’t force an execution. Delete the target file if parameter path is absent

@c

Copy the file. If the target file name is the same as that of the specified file to which it will be moved, the copy fails

@p

path is relative to the main directory when it is a relative path; default is relative to fn’s parent directory

Return value:  

Boolean value

Example:

 

A

 

1

=movefile("E://test.property","D://testfile.property")

Move the file to testfile.property file under root directory on driver D.

2

=movefile("D://testfile.property","file.property")

D://testfile.property is renamed file.property.

3

=movefile("D://file.property")

Delete file.property.

4

=movefile@y("E://test1.property","D://testfile1.property")

The file testfile1.property already exists. Force the move and override the original file.

5

=movefile@c("D://testfile1.property","file.property")

Copy the file, instead of renaming it

6

=movefile@cy("E://test2.property","D:// file.property")

file.property already exists. Force the copy and override the original file.

7

=movefile@y("D://testfile1.property")

Delete testfile1.property.

8

=movefile@cp("D://testfile1.property","file.property")

Copy the file to the main directory and rename it file.property.

Related function:

f. exists()

f. date()

f. size()

movefile(fn,h;path,hs)

Description:

Move a file from a node to another.

Syntax:

movefile(fn,h;path,hs)

Note:

The function moves file fn on node h, which is the local machine when omitted, to path path on node hs, which can be a node sequence. It renames fn when hs is absent, deletes fn when both path and hs are absent, removes files on hs when path and h are absent but hs is non-null.

Parameter:

fn

A file name

h

A node

path

A path (that contains file name) to which a file is moved, or a file name

hs

A node or a node sequence

Option:

@y

Force moving to overwrite a namesake file while default is failure, and deletion when path is null

@c

Copy the file, and the copy fails if there is already a namesake file

Return value:

Boolean

Example:

 

A

 

1

=movefile("D:/tmp.txt",["192.168.31.165:8281"];"D:/p1",["192.168.31.39:8281"])

Move tmp.txt on node "192.168.31.165:8281" to D:/p1 on node "192.168.31.39:8281".

2

=movefile("D:/t1.txt";"D:/p1",["192.168.31.39:8281","192.168.31.46:8281"])

Move t1.txt, which is a local file as parameter h is absent, to a sequence of nodes.

3

=movefile("D:/t2.txt",["192.168.31.165:8281"];"t2_new.txt")

Rename t2.txt on the specified node t2_new.txt since parameter hs is absent.

4

=movefile("D:/t2_new.txt",["192.168.31.165:8281"];)

Delete the specified file since both parameter path and parameter hs are absent.

5

=movefile("D:/p1/tmp.txt";,["192.168.31.39:8281"])

Delete D:/p1/tmp.txt on node "192.168.31.39:8281" since parameter h and parameter path are absent but parameter hs is non-null.

6

=movefile("emp.ctx",["192.168.31.165:8281"];"D:/p1",["192.168.31.39:8281"])

Move 2.emp.ctx in a homo-name files group on node "192.168.31.165:8281" to D:/p1 on node "192.168.31.39:8281".

7

=movefile@y("D:/tmp.txt";"D:/p1",["192.168.31.39:8281"])

@y option is used to force moving the file to overwrite the namesake file.

8

=movefile@y("D:/p1/tmp.txt";,["192.168.31.39:8281"])

@y option is used to force the deletion of the specified file when parameter path is absent.

9

=movefile@c("City.txt",["192.168.31.165:8281"];"D:/p1",["192.168.31.39:8281"])

Use @c option to copy the specified file.

10

=movefile@cy("City.txt";"D:/p1",["192.168.31.39:8281"])

Use @c@y options to force moving the specified file to overwrite the namesake file D:/p1/City.txt on node "192.168.31.39:8281".