[fpc-pascal] Problems with moving/renaming file using sysutils.renamefile

Reinier Olislagers reinierolislagers at gmail.com
Fri Feb 10 13:31:32 CET 2012


On 10-2-2012 13:09, Jonas Maebe wrote:
> 
> On 10 Feb 2012, at 12:19, Reinier Olislagers wrote:
> 
>> Trying to move a file (and rename it at the same time):
>>
>> //ExtractedCompiler is a string variable
>> //BootstrapCompiler is a string property
>> //I'm using my own version of debugln, not important here
>> debugln('Going to rename/move ' + ExtractedCompiler + ' to ' +
>> BootstrapCompiler);
>> sysutils.DeleteFile(BootstrapCompiler); //ignore errors
>> OperationSucceeded:=renamefile(ExtractedCompiler, BootstrapCompiler);
> 
> Renaming is not the same as moving. Renaming only works if source and
> destination are on the same volume.

Thanks, Jonas.


1. Renaming is not moving???
The help says:
"RenameFile renames a file from OldName to NewName. The function returns
True if successful, False otherwise. Remark: you cannot rename across
disks or partitions."
What does this mean, then?
If you rename from e.g. /etc/b to /var/b, (and assuming they're on the
same partition), you're moving the files from one directory to another,
aren't you?
If you cannot move files between directories at all but only rename
them, the remark in the help does not make sense.
Maybe it helps if something like this is put there:
"RenameFile renames a file from OldName to NewName. The function returns
True if successful, False otherwise. Remark: this function can move
and/or rename files from one directory to another, but you cannot rename
across disks or partitions."

2. What is the function for "properly" moving files in FPC that also
moves between partitions, if one exists?
Or a file copy routine (I've found only Lazarus fileutil.Copyfile)? And
could a link to that be put in the RenameFile help?

3. You were right that I was moving between partitions; apparently
ubuntu has a separate partition for /tmp... I hadn't realized that.

Thanks a lot for helping a poor non-Delphi programmer ;)

Reinier



More information about the fpc-pascal mailing list