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)
 Create folder with date name

Author  Topic 

killtacularmania
Starting Member

22 Posts

Posted - 2010-04-19 : 19:34:03
Hey guys I need to create a folder using sql script on \\myserver\outboundfiles\ with todays date attach to the folder name I want so the folder should look like this if the script was ran today

newfolder04192010

thanks for any help

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-19 : 20:52:39
Try something like this:

DECLARE @cmd nvarchar(500), @folderName varchar(100)

SET @folderName = 'newfolder' + REPLACE(CONVERT(varchar(10), GETDATE(), 101), '/', '')

SET @cmd = 'mkdir \\myserver\outboundfiles\' + @folderName

EXEC master..xp_cmdshell @cmd

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-20 : 00:57:16
and make sure xp_cmdshell is enabled if its not already

http://www.mssqltips.com/tip.asp?tip=1020

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-20 : 12:07:01
A faster way to enable it: http://weblogs.sqlteam.com/tarad/archive/2006/09/14/12103.aspx

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -