in reply to rename

The safe way to do this is to use the link/unlink commands. (pseudocode below)
link file to new name/location
if error
    handle error
else
    unlink old filename/location
note that this won't work if you are renaming across partitions on UNIX (but then neither will the rename command).