If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Renaming a local file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-07-04, 04:28
subhasishray subhasishray is offline
Registered User
 
Join Date: Oct 2003
Posts: 83
Renaming a local file

Suppose I have an Excel file in D:\Test with the name a.xls.
Can I rename that excel file from QA of SQL SERVER in the same location or any other location?
Subhasish
Reply With Quote
  #2 (permalink)  
Old 01-07-04, 05:13
LuckyLee LuckyLee is offline
Registered User
 
Join Date: Jan 2004
Location: Sacramento, CA
Posts: 5
Talking

You can perform any dos commands via SQL using xp_cmdshell. You must ensure the SQL server has permissions to the location where the file resides if that location is not on the SQL server.

From QA type:

xp_cmdshell 'rename D:\Test.xls Test2.xls'

That should do the trick.

-Lee
MS SQL 2000 dba
Verizon Wireless
Reply With Quote
  #3 (permalink)  
Old 01-07-04, 10:24
rohitkumar rohitkumar is offline
Registered User
 
Join Date: Sep 2003
Location: New York, NY
Posts: 136
you might even have an activex task to do this in your DTS package. Here is the code
======================================
Function Main()
Dim fs, MyFile
Dim FileLocation
Dim FileName
Dim FileInfo

FileLocation = "D:\Test\"
FileName = "a.xls"
FileInfo = FileLocation & FileName

Set fs = CreateObject("Scripting.FileSystemObject")

If (fs.FileExists(FileInfo)) Then
fs.MoveFile (FileInfo),(FileLocation & "new_name.xls")
set fs=nothing
Main = DTSTaskExecResult_Success
exit function
Else
Main = DTSTaskExecResult_Failure
exit function
End If

End Function
===========================================
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On