Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin.
Search for scripts directly from SSMS, and instantly access any saved scripts in your
SSC briefcase from the favorites tab.
Download now (direct download link)
Thank this author by sharing:
By Simon Facer,
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)
@Folder = 'D:\SQL Log\'
,@FileName = 'Full Backups.log'
,@NewFileName = NULL
,@DateTimeType = 'Created'
,@Debug = 0
how to create folder at runtime using part of filename
Pass a folder name to this SP and it will create the folder for you.
Script to create datestamp folder causing issue
Error....While creating Folder through SQL
Create, Rename, Delete file folder thru SQL