/*
Get the last object access date
@ Filepath: file path, for example, C: \ 1.txt
@ Filedate: Last file access date
Call example:
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 = ' File does not exist '
Return
End
Exec Sp_oamethod @ OBJ , ' GetFile ' , @ File Output, @ Filepath
Exec Sp_oagetproperty @ File , ' Datelastaccessed ' , @ Filedate Output
Go
/*
Get the last file modification date
@ Filepath: file path, for example, C: \ 1.txt
@ Filedate: last modification date of the file
Call example:
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 = ' File does not exist '
Return
End
Exec Sp_oamethod @ OBJ , ' GetFile ' , @ File Output, @ Filepath
Exec Sp_oagetproperty @ File , ' Datelastmodified ' , @ Filedate Output
Go