Hi
How can I create a Folder (eg. C:\MyNewFolder) using SQL Query?
Technology Tips and News
Hi
How can I create a Folder (eg. C:\MyNewFolder) using SQL Query?
EXEC
xp_cmdshell 'MD C:\MyNewFolder' Chrishey ..u can create a file using FSO ..n operate further..
hey chris .
i tried this in my query analyzer of sql2000 its not wrking..
the error is..
Could not find stored procedure 'xp_cmdshell'. even i tried using dbo.xp_cmdshell not wrking..
reply plz..
thanks
All Extended Procedures reside in the master database, so try this:
EXEC master.dbo.xp_cmdshell 'MD C:\MyNewFolder'Chris |
Chris Howarth wrote: | |
|
Thanks Chris
It work perfect, Im using SQL EXPRESS 2005
Is there a way to do this?
Code Snippetdeclare
@Location nvarchar(50)set
@Location = 'C:\mynewfolder'EXEC
master.dbo.xp_cmdshell 'MD ' + @LocationIm getting the following Error
Code Snippet
Msg 102, Level 15, State 1, Line 3 Incorrect syntax near '+'.
declare @cmdpath nvarchar(60)
set @cmdpath = 'MD '+ @Location
exec master.dbo.xp_cmdshell @cmdpath
celobateira wrote: | |
|
Its working, thank you
Hi,
I added some code in order to get the result from the xp_cmdshell command
This returns null if successfull, if an error occurs returns the error message. May be useful instead of getting an sql error
Code Snippet
declare
set
@Location = N'C:\Temp\Temp5'set
@cmdpath = 'MD '+ @LocationCreate
table #result(
result
nvarchar(255))
insert
into #result (result) exec master.dbo.xp_cmdshell @cmdpathselect
@message = ISNULL(@message + ' - ','') + result from #result where result is not nullselect
@messagedrop
table #resultEralper
thxx chris.. its working ....
thx a lott
Hi,
How Can I verify folder existing or not : if not exists , need to create the folder. can any one give code for that one.
You can use xp_fileexist extended system procedure:
http://stackoverflow.com/questions/11740000/check-for-file-exists-or-not-in-sql-server
http://www.mssqltips.com/sqlservertip/1272/file-validation-in-sql-server-with-xpfileexist-stored-procedure/You can use
declare @FilePath varchar(100)
set @FilePath = 'D:\FolderTest'
EXEC master.dbo.xp_create_subdir @FilePath
very simple and easy