SQL Server Central is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
Search:  
 
 

Proc to Rename a file

By Simon Facer, 2008/06/17

Total article views: 913 | Views in the last 30 days: 843

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

By Simon Facer, 2008/06/17

Total article views: 913 | Views in the last 30 days: 843
Your response
 
 
Related tags

Miscellaneous     T-SQL    
SQL Server 2000     T-SQL Aids    
SQL Server 2005    
 
Like this? Try these...

SMS Script

By Jay Dave | Category: Administration
| 675 reads
Already registered?  

Free registration required

To read the rest of this article, and access thousands of other articles, we ask you to register on the site and subscribe to our newsletters.

Register

E-mail address:
Password:
Password (confirm):

  

Subscriptions

We ask you to register on the site and subscribe to our newsletters. Subscribing to our newsletters gets you:

  • ALL of our content (thousands of articles, scripts, and forum postings)
  • A daily newsletter (example)
  • A weekly news round up (example)
  • The opportunity to ask and answer questions in our forums
  • A daily Question of the Day to test and help you increase your knowledge of SQL Server.

We ask that you give the newsletter a try for a week. Over 200,000 SQL Server Professionals a day find it entertaining and useful. If not, you are welcome to unsubscribe at anytime.

Steve Jones
Editor, SQLServerCentral.com