• Nice, but I have to admit it seems a very complicated solution.  Circumstances are probably different but I used a bit of t-sql to do a very similar thing.  In my case so I could run a job that automatically identifies and then restores the latest backup of a database to a beta server.  It relies on xp_cmdshell and hardcoded folder locations which isn't great, but its fast and short. 

    I've included the complete code below, at the very least it might provide someone with an alternative means that is easily integrated into a maintenance job or stored proc.

    -- output a command shell directory listing to a text file, sorting by date

    EXEC master..xp_cmdshell 'dir "\\share\FolderOfInterest\*.bak" /b /O-D > d:\output.txt', no_output

     

    -- create a temporary table to store the directory listing

    CREATE TABLE #tmpDirList (strFileName varchar(100))

    -- bulk upload the directory listing to the temporary table

    BULK INSERT #tmpDirList FROM 'D:\output.txt' WITH (DATAFILETYPE = 'char', ROWTERMINATOR = '\n')

    -- create a variable to store the latest file to

    DECLARE @strFileSource varchar(100)

    SET @strFileSource = (SELECT TOP 1 strFilename FROM #tmpDirList)

     

     

    Ryan
    -----------------
    www.quadrus.com