The calls to this routine are simple, it's compiled to master but it could go anywhere, just change the prefix from sp_ !!!
The parameters are:
@Folder The folder where the file exists. REQUIRED.
@FileName The file to be renamed. REQUIRED.
@NewFileName The new file name. OPTIONAL - If not specified (NULL or empty / space) -
add a DateTime literal (_yyyymmddhhnnss) to the filename, as in filename.ext becomes filename_yyyymmddhhnnss.ext
@DateTimeType One of (not case sensitive): CREATED File Created DateTime, MODIFIED Modified DateTime, NULL / '' NULL or spaces. Value used to generate the DateTime literal for the default generated filename. OPTIONAL - If not specified (NULL or empty / space) - use GETDATE().
@Debug Switch to determine if debugging information should be output OPTIONAL - defaults to 0 (No).
An example of a call to this proc, to rename file 'D:\SQL Log\Full Backups.log' to 'D:\SQL Log\Full Backups_200805010600.log' (using the file creation date-time of 05/01/2008 06:00am)
EXECUTE .[sp_RenameFile]
@Folder = 'D:\SQL Log\'
,@FileName = 'Full Backups.log'
,@NewFileName = NULL
,@DateTimeType = 'Created'
,@Debug = 0