Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Move and Rename file

$
0
0

I am trying to move and rename all the files with extension csv in the folder. 

c:\folder\a.csv c:\Newfolder\a20141151011.csv  datetime append after moving
c:\folder\b.csv c:\Newfolder\b20141151011.csv 

I cannot use ssis it has to be done in TSQL 


DECLARE @FILELOCATION VARCHAR(250)
DECLARE @FINALLOCATION VARCHAR(250)
DECLARE @FILENAME VARCHAR (250) = '*.CSV'
DECLARE @DESTINATIONFILENAME VARCHAR (250) --= @filename + '.txt'
SET @FILELOCATION = 'C:\folder\'
SET @FINALLOCATION = 'C:\Newfolder\' 
DECLARE @C VARCHAR (2000)
SET @C = 'MOVE ' + @FILELOCATION + @FILENAME  +' ' + @FINALLOCATION + @DESTINATIONFILENAME 

exec master.dbo.xp_cmdshell@C

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>