How do I get a list of filenames from a populated folder?

  • Hi,

    can I run xp_cmshell to return a value of a filename that exists in a folder?

    I'm writing a script that will run a DTS package and would like to provide the filename as a parameter.

    As a follow on, the script will have a cursor that will loop through a number of filenames that might populate a folder.

    Any help welcome,

    Eamon

  • Yes, I have done that. I generally make a temp table, then execute something like

    SET @listCom = 'DIR /b ' + @yourFolderName + '*.foo'

    INSERT INTO #dirlist ( fname ) EXEC master..XP_CMDSHELL @listCom

    Then you can query the table. Beware that the result set might just be "File Not Found"

  • perfect !

    Thanks alot Merrill,

    Eamon

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

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