Perhaps this will help you. Last night I wrote a code which is meant to auto-generate a file and attach it to the node. When the node is about to be saved, the function removes the uploaded file from the node and creates and attaches the new file.
In your case, you might be able to just update the file name with file_copy and resetting the filefield.
function MODULE_node_presave($node) {
/*
* Out with the old - detach file object
*/
if (isset($node->field_filefieldname['und'][0]['fid'])) {
file_delete(file_load($node->field_filefieldname['und'][0]['fid']));
}
unset($node->field_filefieldname['und'][0]); //just for good measure
/*
* In with the new
*/
$filename = 'newfilename.dot';
$filepath = conf_path().'/files/yourpath/';
$touchout = $node->title;
$tempFile = file_directory_temp().'/'.$filename;
file_put_contents($tempFile, $touchout);
$file = (object) array(
'uid' => 1,
'uri' => $tempFile,
'filemime' => file_get_mimetype($tempFile),
'status' => 1,
'display' => 1,
);
/*
* File save operation, puts file in /sites/default/files and records update in db
*/
if (file_prepare_directory($filepath, FILE_CREATE_DIRECTORY)) {
$file = file_copy($file, 'public://path/'.$filename, FILE_EXISTS_REPLACE);
}
/*
* Reattaches our severed file, good as new.
*/
$node->field_filefieldname['und'][0] = (array)$file;
}
?>