I am trying to create folder using xp_cmdshell it works fine...But the problem is I cant consider a space char
in my folder name (i.e., Folder Name) the below script i used for .... It just create a folder ABC..
Why it's not create the folder with the full name i.e., ABC 1-X ...I don't know why.
--EXEC spCreateF0lder 'C:\ComName\Test\' ,'ABC X-1'
CREATE PROCEDURE spCreateF0lder
DECLARE @SqlScript VARCHAR (MAX)
SET @SqlScript = 'EXEC master.dbo.xp_cmdshell ''' + 'mkDir ' + @DefaultPath + @FolderName + ''''
Md. MarufuzzamanSunday, December 27, 2009 12:39 PM
If you want to create a folder named "Test" in C drive, below code will work perfectly...
master.dbo.xp_cmdshell 'mkDir C:\Test'
If you want to create a folder that contains space in its name, or if the path contains space(s), then this will not work. See below:
master.dbo.xp_cmdshell 'mkDir C:\Test Folder'
This will give you error because "Test Folder" contains a space between the words Test & Folder.
If you want to create a folder named "Test" underneath "C:\Program Files" folder with below code, you will get the same error:
master.dbo.xp_cmdshell 'mkDir C:\Program Files\Test'
To avoid the error creating a folder with space in the name, or space in the path, just use double quotations at the both sides of the full path like below:
master.dbo.xp_cmdshell 'mkDir "C:\Test Folder"'
master.dbo.xp_cmdshell 'mkDir "C:\Program Files\Test"'
But this will work for the first example as well:
master.dbo.xp_cmdshell 'mkDir "C:\Test"'
Hope this helps...
-Jahedur RahmanFriday, September 03, 2010 6:07 AM
Jahedur, Hedda is just a spammer whose goal is to add hidden link seo spam to forums.
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVPFriday, January 28, 2011 5:32 AM