22,209
社区成员
发帖
与我相关
我的任务
分享
SQL codedeclare @i int
exec @i = master.dbo.xp_cmdshell 'if exist "D:/aaa.txt" (echo 1) else (echo 0)',no_output
if @i = 0 --> exists
if @i = 1 --> not exists
declare @i int
exec @i = master.dbo.xp_cmdshell 'if exist "D:/aaa.txt" (echo 1) else (echo 0)',no_output
if @i = 0 --> exists
if @i = 1 --> not exists
declare @i int
exec @i = master.dbo.xp_cmdshell 'dir D:/aaa.txt',no_output
if @i = 0 --> exists
if @i = 1 --> not exists
DECLARE @err INT,@fso INT,@fleExists BIT,@file VARCHAR(100)
SET @file='d:/aaa.txt'
EXEC @err=sp_OACreate 'Scripting.FileSystemObject',@fso OUTPUT
EXEC @err=sp_OAMethod @fso, 'FileExists',@fleExists OUTPUT,@file
EXEC @err = sp_OADestroy @fso
IF @fleExists=0
PRINT '"' + @file + '" not exists'
ELSE
PRINT 'OK'
set nocount on
create table #([output] varchar(8000))
declare @file varchar(1000)
set @file='d:\aaa.txt'
declare @sql varchar(1000)
set @sql='dir '+@file
insert into # exec master..xp_cmdshell @sql
if exists(select 1 from # where [output]='找不到文件')
print '不存在该文件!'
else
print '存在该文件!'
drop table #