/*
擷取檔案最後訪問日期
@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