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 2008 Forums
 SQL Server Administration (2008)
 Create folder and copy files using xp_cmdshell

Author  Topic 

sqlpal2007
Posting Yak Master

200 Posts

Posted - 2011-12-20 : 09:17:10
Hello All,

I have to copy file daily from SQL job to the file server. The SQL job should create a folder first day of each month as 'Jan', 'Feb' etc.. and upload the file accordingly.

If it's the last day of the month then it should create year folder '2012' and then month folder 'Jan' then copy the output of select table.

How do I do this in xp_cmdshell? Can anyone give me a example or sample code?

Thanks,

X002548
Not Just a Number

15586 Posts

Posted - 2011-12-20 : 10:04:37
exec master..xp_cmdshell 'md folder'

then if you need dynamic

@cmd = whatever dynamic you want to set

exec master..xp_cmdshell @cmd



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -