tsql or something to get if file exists and date of file

  • hello everyone,

    trying to to find 2 things, 1. i am trying to write a tsql statement that will check if the file exists, but also check if the file exists today, like if it was created today... and 2nd, if it is not, and its an old file, like say from yesterday, then email me...

    i got the 2nd part down, i am stuck on finding out how i can get the file date, i looked at:

    INSERT INTO #tmp EXEC xp_cmdshell

    the code above (and yes its not all complete) isnt cutting it, i need just to put the path, file and date created of the file into a temp table so i can query it... any ideas?

  • Something like this?

    CREATE TABLE #tmp( output nvarchar(max));

    INSERT INTO #tmp

    --Change Path

    EXEC xp_cmdshell 'dir C:\Users\lcazares\Documents\Statement.pdf /TC'; --Uses /TC for creation date

    SELECT CAST( LEFT( output, 10) AS datetime)

    FROM #tmp

    WHERE output LIKE '[0-9][0-9]/[0-9][0-9]/[0-9][0-9][0-9][0-9]%';

    DROP TABLE #tmp;

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • ahh yes big thank you 🙂

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply