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
  • 相关阅读:
    EF写in
    1707. [Usaco2007 Nov]tanning分配防晒霜
    BZOJ 1706. [usaco2007 Nov]relays 奶牛接力跑
    1705. [Usaco2007 Nov]Telephone Wire 架设电话线
    BZOJ1704. [Usaco2007 Mar]Face The Right Way 自动转身机
    Codeforces Manthan, Codefest 19 (open for everyone, rated, Div. 1 + Div. 2)
    BZOJ1702. [Usaco2007 Mar]Gold Balanced Lineup 平衡的队列
    P2876 [USACO07JAN]解决问题Problem Solving
    BZOJ 1908. Pku2054 UVA1205 Color a Tree
    P4280 [AHOI2008]逆序对
  • 原文地址:https://www.cnblogs.com/RobotTech/p/1067905.html
Copyright © 2011-2022 走看看