Rename File

Discussions related to Visual Prolog
Loffy
Active Member
Posts: 47
Joined: 15 Aug 2019 11:32

Rename File

Unread post by Loffy » 21 Aug 2019 9:07

I have tried to find a replacement for the old renamefile/2 predicate without luck so far.

Any hints?

Regards,

Loffy

Harrison Pratt
VIP Member
Posts: 285
Joined: 5 Nov 2000 0:01

Re: Rename File

Unread post by Harrison Pratt » 21 Aug 2019 12:25

See file::move/2 and file::move/3

Code: Select all

move : (     string Filename,     string Destination).
Moves file to another location.

Description
The predicate moves(renames) a file specified by Filename to the location, specified by Destination path.
If Destination is a new file name, then the file will be moved to a new location and renamed simultaneously, otherwise it's assumed that Destination is an existing directory and the file will be moved into it.
If Destination already contains file with the same name, then the file will be overwritten.
Both names may have the full-qualified or relative paths.

Exceptions
nativeCallException is raised if internal API function call failed

Loffy
Active Member
Posts: 47
Joined: 15 Aug 2019 11:32

Re: Rename File

Unread post by Loffy » 21 Aug 2019 12:41

Harrison,

Thanks again.

Regards,

Loffy

User avatar
Tonton Luc
VIP Member
Posts: 501
Joined: 16 Oct 2001 23:01

Re: Rename File

Unread post by Tonton Luc » 19 Nov 2019 13:28

Hi,

You can also use :

Code: Select all

fileName::setName("C:\\myFolder\\oldName.txt","NewName"),
:wink:

Harrison Pratt
VIP Member
Posts: 285
Joined: 5 Nov 2000 0:01

Re: Rename File

Unread post by Harrison Pratt » 19 Nov 2019 22:39

setName/2 only changes a string containing a fully qualified file name. It doesn't do anything to a file.

It belongs to the same family of functions as setPath/2and setExtension/2.

Post Reply