zoukankan      html  css  js  c++  java
  • 在SQL Server中取得操作系统文件的最后修改日期 [Z]

    /*
      获取文件最后访问日期
      @filepath   文件路径,如:   c:\1.txt
      @filedate   文件最后访问日期

      调用示例:
      declare   @dt   varchar(20)
      exec   getFileLastAccessDate   'c:\1.txt',@dt   output
      select   @dt
    */
    create   procedure   getFileLastAccessDate
      
    @filepath   varchar(4000),
      
    @filedate   varchar(20)   output
    as
      
    declare   @obj   int,@file   int
      
    declare   @fileexists   varchar(10)
      
    exec   sp_oacreate   'Scripting.FileSystemObject',@obj   output
      
    exec   sp_oamethod   @obj,'FileExists',@fileexists   output,@filepath
      
    if   @fileexists='False'
      
    begin
        
    set   @filedate='文件不存在'
        
    return
      
    end
      
    exec   sp_oamethod   @obj,'GetFile',@file   output,@filepath
      
    exec   sp_oagetproperty   @file,'DateLastAccessed',@filedate   output
    go
    /*
      获取文件最后修改日期
      @filepath   文件路径,如:   c:\1.txt
      @filedate   文件最后修改日期

      调用示例:
      declare   @dt   varchar(20)
      exec   getFileLastModified   'c:\1.txt',@dt   output
      select   @dt
    */
    create procedure getFileLastModified
      
    @filepath varchar(4000),
      
    @filedate varchar(20) output
    as
      
    declare   @obj   int,@file   int
      
    declare   @fileexists   varchar(10)
      
    exec   sp_oacreate   'Scripting.FileSystemObject',@obj   output
      
    exec   sp_oamethod   @obj,'FileExists',@fileexists   output,@filepath
      
    if   @fileexists='False'
      
    begin
        
    set   @filedate='文件不存在'
        
    return
      
    end
      
    exec   sp_oamethod   @obj,'GetFile',@file   output,@filepath
      
    exec   sp_oagetproperty   @file,'DateLastModified',@filedate   output
    go
  • 相关阅读:
    xxx
    cdq分治入门--BZOJ1176: [Balkan2007]Mokia
    cdq分治入门--BZOJ3262: 陌上花开
    本月题量 171122晚-171222午
    cdq分治入门--BZOJ1492: [NOI2007]货币兑换Cash
    NOIP2017游记
    xx
    CF601D:Acyclic Organic Compounds
    LOJ#539. 「LibreOJ NOIP Round #1」旅游路线
    composer常用的一些命令参数说明
  • 原文地址:https://www.cnblogs.com/RobotTech/p/1067905.html
Copyright © 2011-2022 走看看