Wednesday, March 21, 2012

Rename a text file

hi,
How do I rename a text file through Sql scheduled job?
Thnaksexec master..xp_cmdshell 'ren c:\filename.txt newfilename.txt';
Two notes:
(1) the service account for SQL Server Agent must have read/write
permissions on the target folder(s).
(2) In SQL Server 2005, you have to go through a hoop to enable xp_cmdshell
(it is disabled by default).
A
"mecn" <mecn2002@.yahoo.com> wrote in message
news:eTLvEYtPGHA.4916@.TK2MSFTNGP10.phx.gbl...
> hi,
> How do I rename a text file through Sql scheduled job?
> Thnaks
>|||Thanks a lot
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:eTirogtPGHA.4044@.TK2MSFTNGP15.phx.gbl...
> exec master..xp_cmdshell 'ren c:\filename.txt newfilename.txt';
> Two notes:
> (1) the service account for SQL Server Agent must have read/write
> permissions on the target folder(s).
> (2) In SQL Server 2005, you have to go through a hoop to enable
> xp_cmdshell (it is disabled by default).
> A
>
>
> "mecn" <mecn2002@.yahoo.com> wrote in message
> news:eTLvEYtPGHA.4916@.TK2MSFTNGP10.phx.gbl...
>|||Sorry, I forgot, When I rename the txt file i need to add datetime at the
end of the file name.
Thanks
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:eTirogtPGHA.4044@.TK2MSFTNGP15.phx.gbl...
> exec master..xp_cmdshell 'ren c:\filename.txt newfilename.txt';
> Two notes:
> (1) the service account for SQL Server Agent must have read/write
> permissions on the target folder(s).
> (2) In SQL Server 2005, you have to go through a hoop to enable
> xp_cmdshell (it is disabled by default).
> A
>
>
> "mecn" <mecn2002@.yahoo.com> wrote in message
> news:eTLvEYtPGHA.4916@.TK2MSFTNGP10.phx.gbl...
>|||then
exec master..xp_cmdshell 'ren c:\filename.txt newfilename_' +
replace(convert(varchar, getdate(), 120), ':', '_') + '.txt'
or something of this kind
Peter|||Thanks,
I tried, i got this error: Line 2: Incorrect syntax near '+'
"Rogas69" <rogas69@.no_spamers.o2.ie> wrote in message
news:OMpTx1tPGHA.3936@.TK2MSFTNGP12.phx.gbl...
> then
> exec master..xp_cmdshell 'ren c:\filename.txt newfilename_' +
> replace(convert(varchar, getdate(), 120), ':', '_') + '.txt'
> or something of this kind
> Peter
>|||you want to form the @.cmd before calling xp.
e.g.
declare @.cmd sysname
set @.cmd='ren c:\filename.txt newfilename_' + replace(convert(varchar,
getdate(), 120), ':', '_') + '.txt'
exec master..xp_cmdshell @.cnd
-oj
"mecn" <mecn2002@.yahoo.com> wrote in message
news:ex5HAIvPGHA.3728@.tk2msftngp13.phx.gbl...
> Thanks,
> I tried, i got this error: Line 2: Incorrect syntax near '+'
> "Rogas69" <rogas69@.no_spamers.o2.ie> wrote in message
> news:OMpTx1tPGHA.3936@.TK2MSFTNGP12.phx.gbl...
>|||thanks,
That works
"oj" <nospam_ojngo@.home.com> wrote in message
news:%234XsKMvPGHA.5044@.TK2MSFTNGP09.phx.gbl...
> you want to form the @.cmd before calling xp.
> e.g.
> declare @.cmd sysname
> set @.cmd='ren c:\filename.txt newfilename_' + replace(convert(varchar,
> getdate(), 120), ':', '_') + '.txt'
> exec master..xp_cmdshell @.cnd
> --
> -oj
>
> "mecn" <mecn2002@.yahoo.com> wrote in message
> news:ex5HAIvPGHA.3728@.tk2msftngp13.phx.gbl...
>

No comments:

Post a Comment