Con queste poche dighe di codice è possibile verificare – unicamente mediante T-SQL – l’esistenza o meno di un file:
create table [#cmdoutput]
(
[output] nvarchar(1024)
)
go
[output] nvarchar(1024)
)
go
insert into [#cmdoutput] ([output])
exec xp_cmdshell ‘dir /b \\tauceti2\c$\autoexec.bat’
go
declare @exists int
select @exists = count(*) from #cmdoutput where [output] is not null
if (@exists > 0) print ‘Exists’ else print ‘Not Exists’
go
drop table [#cmdoutput] go