Technical Article

File create/modified/accessed date w/out scripting

,

This script demonstrates a simple way to query a files create, modified or last accessed date without using a scripting and is availble in TSQL using xp_cmdshell.

CREATE TABLE #tempTbl (
    [idx] [int] IDENTITY (1,1) NOT NULL,
    [val] [varchar] (8000) NULL
)

/* 
      /T          Controls which time field displayed or used for sorting
      timefield   C  Creation
                  A  Last Access
                  W  Last Written

    Replace /T:C with the date value you want.

    Just replace C:\NTDETECT.COM with the path and name of the file you want. 
*/INSERT INTO #tempTbl (val) EXEC master..xp_cmdshell @Val = 'DIR C:\NTDETECT.COM /T:C'

SELECT 
    CAST(LEFT(val,18) + 'm' as DATETIME) dateval 
FROM 
    #tempTbl 
WHERE 
    val IS NOT NULL AND 
    val NOT LIKE '%Volume %' AND 
    val NOT LIKE '%Directory %' AND 
    val NOT LIKE '%File(s) %' AND 
    val NOT LIKE '%Dir(s) %'

DROP TABLE #tempTbl

Rate

You rated this post out of 5. Change rating

Share

Share

Rate

You rated this post out of 5. Change rating