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)
 using xp_cmdshell

Author  Topic 

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2007-12-27 : 14:09:18
well.. I need to append all text files in a specified directory to a file called abcde.txt using xp_cmdshell

(if file already exits then it should overwrite it without any warning)

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-12-27 : 14:11:35
You can append files using the type DOS command.

type C:\Directory1\*.* > C:\abcde.txt

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2007-12-27 : 14:18:27
doesnt work strangely.. copies the existing files twice that ways ...

besides i also need to trim the first 1 row of both files and then append the remaining rows into another file called abcde.txt
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-12-27 : 22:23:37
Use this:

type C:\Directory1\*.* >> C:\abcde.txt
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-12-27 : 23:01:13
> will work just fine, not sure why sakets is having problem. I just ran a test and it works great.

>> appends if the file exists already.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -