Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Trying to change the name of a file on a directory

Author  Topic 

itmasterw
Yak Posting Veteran

90 Posts

Posted - 2009-12-11 : 10:27:02
Hi,
I used to do this but cannot rember how, I just know I did it wiht XP_CMPSHELL. I am trying to change the name of a file form with in my stored procedure.
If anyone can point me in a direction(a web site) here or has the code I would really appreciate it.
Thank you

ITM

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-12-11 : 10:40:09
Look for the syntax of X_CMDSHELL and look at the syntax on how to rename a file.
What is the problem?
exec master.dbo.xp_cmdshell "ren filename newfilename"



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

itmasterw
Yak Posting Veteran

90 Posts

Posted - 2009-12-11 : 10:51:39
So are you saying that this is htis how I would do it:

exec master.dbo.xp_cmdshell "ren filename newfilename"

exec master.dbo.xp_cmdshell "ren c:\test1.txt c:\test2.txt"


ITM
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-12-11 : 10:53:49
Yes and the command can also be a variable if needed.
exec xp_cmdshell @command


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

itmasterw
Yak Posting Veteran

90 Posts

Posted - 2009-12-11 : 11:09:52
Hi
I get incorrect syntext when I do do this and I tryed both single and double quots?

ITM
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-12-11 : 11:20:57
you don't specify the drive letter in the target of the rename:

xp_cmdshell 'c:\test1.txt test2.txt'
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-12-11 : 11:24:03
That's true.
Sorry for confusing...


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2009-12-11 : 11:27:24
I don't think you confused anyone Fred. Was just adding extra info to what you already posted. In fact you DID tell OP to look up syntax on ren command
Go to Top of Page

itmasterw
Yak Posting Veteran

90 Posts

Posted - 2009-12-11 : 11:31:25
I got it to work thanks.

ITM
Go to Top of Page
   

- Advertisement -