Function to get the name of a file

  • I was curious if there was any SQL function that would get the name of a file in a directory, if i give that directory, as well as which file i wanted and the way i wanted the files sorted. I need to bring back a file name in order to parse some information out of that name. I can do this in a script, but i already have an application executing stored procedures and sql statements for me, and i wanted to try and keep this inside SQL.

    If anyone has any ideas, i would appreciate your help.

    thanks,

    chris

  • There;s a number of undocumented features in SQL Server 2000 (that is, they probably wont exist in the next version, so try not to use them!).

    There's the master..xp_fileexist extended sproc which uses the syntax

    EXECUTE xp_fileexist filename [, file_exists INT OUTPUT]

    example:

    DECLARE @intFileExists
    SET @intFileExists = 0
    EXEC master..xp_fileexist 'c:\boot.ini', @intFileExists OUTPUT
    SELECT @intFileExists as DoesTheFileExist

    There's also one called master..xp_dirtree which returns a directory listing. You need to chuck that one into a tablet to make the results useful though.


    Julian Kuiters
    juliankuiters.id.au

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

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