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

解决方案 »

  1.   

    declare @FileExist table(Col1 int,Col2 int,Col3 int)insert @FileExist exec xp_fileexist @Pathselect 1 from @FileExist where Col2=0--判斷
      

  2.   

    xp_fileexist在2000中也是个扩展存储过程,估计2005取消了吧,不知道这个情况.
      

  3.   

    大哥,xp_fileexist在2005中还存在这个存储过程?
    麻烦你先自己测试下好木?
      

  4.   

      exec master..xp_cmdshell 'dir "I:\www.jingying.me_vss\YX_UpFile\Small\b0000920333.jpg"'
      

  5.   

    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 '文件不存在'
      

  6.   

    差了个右括号:
    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 '文件不存在'
      

  7.   

    刚测试过, SQL 2008 R2亦有exec xp_fileexist 'C:\boot.ini'File Exists File is a Directory Parent Directory Exists
    ----------- ------------------- -----------------------
    0           0                   1
      

  8.   

    --是否允许运行系统存储过程xp_cmdshell
    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 语句进行安装。
    */
      

  9.   

    exec xp_fileexist 'C:\boot.ini'/*文件?  文件?  父目录
    ---- ---- ----
    0    0    1(1 行受影响)
    */
      

  10.   


    你换一个带文件夹的试试?exec xp_fileexist 'D:\图\back.jpg'
      

  11.   

    exec xp_fileexist 'D:\图\back.jpg'
    /*文件?  文件?  父目录
    ---- ---- ----
    0    0    0(1 行受影响)*/
      

  12.   


    當然有,一直在用。。樓主的是什麼版本這是在master庫里的
      

  13.   

    SELECT * FROM master.dbo.sysobjects WHERE name='xp_fileexist'--查看是否存在
      

  14.   


    exec master..xp_fileexist 'd:\db1.mdb'
    测试,在05里和08里都能运行.
      

  15.   

    sp_configure 'show advanced options',1
    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 语句进行安装。
    */
      

  16.   

     
    我说你不要查根目录下的文件,查下一级也就是用文件夹装起的文件,比如 d:\新建文件夹\123.jpg 这种,你试试?
      

  17.   

    exec xp_fileexist 'D:\Program Files\WinRAR\Default.SFX'
    /*文件?  文件?  父目录
    ---- ---- ----
    1    0    1(1 行受影响)*/
      

  18.   

    有i盘的呢,2个硬盘,换成d盘的可以,但是i盘的就是不行“系统找不到指定的路径。”
    还有就是这个语句查询出来了不看结果怎么判断文件是否存在?

      

  19.   


    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也存在,就是检测不出图片文件来
    换成其他格式的文件可以检测出来,但是图片文件貌似不可以怎么解决啊??
      

  20.   


    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
    */
      

  21.   

    exec xp_fileexist 'D:\Program Files\WinRAR\未命名.jpg'
    /*文件?  文件?  父目录
    ---- ---- ----
    1    0    1(1 行受影响)*/
      

  22.   


    你明白啥了?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
    */
      

  23.   


    exec xp_fileexist 'C:\bea\beahomelist.xml';exec xp_fileexist 'C:\bea\DSCN0953.jpg';/*
    文件? 文件? 父目录
     1    0    1文件? 文件? 父目录
     1     0     1
    */
      

  24.   

    是否是你的JPEG和JPG的问题?
      

  25.   

    这个master..xp_fileexist是针对服务器上的文件系统的.请问你的I:\www.jingying.me_vss\YX_UpFile\Small\b0000920333.jpg这个路径是相对于数据库服务器的吗?如果是你本机的,肯定是不行的.对网络共享,如果权限不够,也是不行的.
      

  26.   


    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也可以用这个过程