2000里面有这个xp_fileexist可以检测,但貌似2005中木有了?
请问2005中怎么检测指定路径的文件是否存在呢?
declare @num int --申明一个接受返回值的变量 YX_UpFile/Small/b0001072300.jpg
EXEC master..xp_fileexist 'I:\www.jingying.me_vss\YX_UpFile\Small\b0000920333.jpg',@num output -- 执行文件存在否的验证 存在返回1 不存在返回0
if(@num = 1) --如果存在就给出提示或做其他功能的实现
begin
print '文件已经存在'
end
else --该文件不存在执行备份操作
begin
print '文件不存在'
end
请问2005中怎么检测指定路径的文件是否存在呢?
declare @num int --申明一个接受返回值的变量 YX_UpFile/Small/b0001072300.jpg
EXEC master..xp_fileexist 'I:\www.jingying.me_vss\YX_UpFile\Small\b0000920333.jpg',@num output -- 执行文件存在否的验证 存在返回1 不存在返回0
if(@num = 1) --如果存在就给出提示或做其他功能的实现
begin
print '文件已经存在'
end
else --该文件不存在执行备份操作
begin
print '文件不存在'
end
麻烦你先自己测试下好木?
insert into #t
exec xp_cmdshell "dir I:\www.jingying.me_vss\YX_UpFile\Small\b0000920333.jpg"
if not exists(select 1 from #t where f='b0000920333.jpg'
print '文件存在'
else
print '文件不存在'
create table #t(f nvarchar(100))
insert into #t
exec xp_cmdshell "dir I:\www.jingying.me_vss\YX_UpFile\Small\b0000920333.jpg"
if not exists(select 1 from #t where f='b0000920333.jpg')
print '文件存在'
else
print '文件不存在'
----------- ------------------- -----------------------
0 0 1
sp_configure 'show advanced options',1
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
go
exec master..xp_cmdshell 'dir "I:\www.jingying.me_vss\YX_UpFile\Small\b0000920333.jpg"'
go
sp_configure 'show advanced options',0
reconfigure
go/*配置选项 'show advanced options' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
配置选项 'xp_cmdshell' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
output
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
系统找不到指定的路径。
NULL(2 行受影响)配置选项 'show advanced options' 已从 1 更改为 0。请运行 RECONFIGURE 语句进行安装。
*/
---- ---- ----
0 0 1(1 行受影响)
*/
你换一个带文件夹的试试?exec xp_fileexist 'D:\图\back.jpg'
/*文件? 文件? 父目录
---- ---- ----
0 0 0(1 行受影响)*/
當然有,一直在用。。樓主的是什麼版本這是在master庫里的
exec master..xp_fileexist 'd:\db1.mdb'
测试,在05里和08里都能运行.
reconfigure
go
sp_configure 'xp_cmdshell',1
reconfigure
go
exec master..xp_cmdshell 'dir "D:\Program Files\WinRAR\Default.SFX"'
go
sp_configure 'show advanced options',0
reconfigure
go/*配置选项 'show advanced options' 已从 0 更改为 1。请运行 RECONFIGURE 语句进行安装。
配置选项 'xp_cmdshell' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
output
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
驱动器 D 中的卷没有标签。
卷的序列号是 9091-BCC1
NULL
D:\Program Files\WinRAR 的目录
NULL
2011/05/31 09:55 96,256 Default.SFX
1 个文件 96,256 字节
0 个目录 36,912,943,104 可用字节
NULL(9 行受影响)配置选项 'show advanced options' 已从 1 更改为 0。请运行 RECONFIGURE 语句进行安装。
*/
我说你不要查根目录下的文件,查下一级也就是用文件夹装起的文件,比如 d:\新建文件夹\123.jpg 这种,你试试?
/*文件? 文件? 父目录
---- ---- ----
1 0 1(1 行受影响)*/
还有就是这个语句查询出来了不看结果怎么判断文件是否存在?
declare @num int --申明一个接受返回值的变量 YX_UpFile/Small/b0001072300.jpg
EXEC master..xp_fileexist 'D:\Program Files\360\360Safe\200942152862.GIF',@num output -- 执行文件存在否的验证 存在返回1 不存在返回0
if(@num = 1) --如果存在就给出提示或做其他功能的实现
begin
print '文件已经存在'
end
else --该文件不存在执行备份操作
begin
print '文件不存在'
end我突然懂了,这个语句是正确的,2005下xp_fileexist也存在,就是检测不出图片文件来
换成其他格式的文件可以检测出来,但是图片文件貌似不可以怎么解决啊??
exec master..xp_fileexist 'D:\Media\长歌一曲.mp3'
/*
文件 文件 父目录
1 0 1
*/
exec master..xp_fileexist 'D:\mywork\vb\sample3-4.exe'
/*
文件 文件 父目录
1 0 1
*/
exec master..xp_fileexist 'J:\Program Files\StarCraft II\sc2manager8.3.6\SC2Manager.exe'
/*
文件 文件 父目录
1 0 1
*/
/*文件? 文件? 父目录
---- ---- ----
1 0 1(1 行受影响)*/
你明白啥了?exec master..xp_fileexist 'J:\化工制图\练习064\培训图片汇总\画线+移动.jpg'
/*
文件 文件 父目录
1 0 1
*/
exec master..xp_fileexist 'D:\实验中心网站\openexp\image\left_top_r1_c2.gif'
/*
文件 文件 父目录
1 0 1
*/
exec xp_fileexist 'C:\bea\beahomelist.xml';exec xp_fileexist 'C:\bea\DSCN0953.jpg';/*
文件? 文件? 父目录
1 0 1文件? 文件? 父目录
1 0 1
*/
DECLARE @result AS INT
EXEC sys.xp_fileexist 'D:\dbbackup\db.bak',@result OUTPUT
IF @result=1
EXEC xp_cmdshell 'xcopy /y D:\dbbackup\db.bak E:\dbbackup\'
ELSE
PRINT '@result=0, This file does not exist'--sql 2008也可以用这个过程