It is 'xp_cmdshell':
http://technet.microsoft.com/en-us/library/ms175046.aspx[
^]
but you may have to configure it:
EXEC sp_configure 'show advanced options', 1
go
reconfigure
go
EXEC sp_configure'xp_cmdshell', 1
go
exec xp_cmdshell 'dir c:\'
of course, you must adapt this procedure usage to your case.
[update]
tested for sql-server 2008 R2 express:
if not exists(select * from tempdb.dbo.sysobjects
where name like '#tmptable_%')
begin
create table #tmptable (dirs varchar(255));
insert into #tmptable(dirs)
values('d:\tmp\'), ('d:\source');
create table #restable (dir_list varchar(255));
end
declare @mydir sysname;
declare @cmd sysname;
declare dircursor cursor for select * from #tmptable;
open dircursor;
fetch next from dircursor into @mydir;
while @@FETCH_STATUS=0
begin
set @cmd='dir '+@mydir+' /b';
insert into #restable(dir_list) exec xp_cmdshell @cmd;
if exists (select * from #restable where dir_list='File Not Found')
print 'not a dir: '+@mydir;
else
print 'exists: '+@mydir;
delete from #restable;
fetch next from dircursor into @mydir;
end
close dircursor;
deallocate dircursor
go