extended stored procedures

  • How can I get a list of all the files that exists in the folder from QA? (extended stored procedures?)

  • 
    
    EXEC master.dbo.xp_cmdshell 'dir c:\MSSQL7'

    Of course, replace c:\MSSSQL7 with whatever directory on the server you want...

  • Thanks for your help!

  • If I do this way I get additional information: date, time, size….

    Is there any way to get only file names?

    I have to load into table just file names. How to process this output information?

    Will the name always starts from fixed position?

  • Exec master.dbo.xp_cmdshell 'dir d:\MSSQL7 /b'

    the '/b' switch should return only the filenames (and subdirectory names) from the directory...

    To list only the files

    Exec master.dbo.xp_cmdshell 'dir d:\MSSQL7 /b/a-d'

    good old DOS commands....

  • OR, another way, just to show you examples...

    
    
    CREATE TABLE #temp (OutputText NVARCHAR(1000))
    --
    INSERT INTO #temp
    EXEC sp_executesql N'exec master.dbo.xp_cmdshell ''dir c:\MSSQL7\Binn'''
    --
    SELECT RIGHT(OutputText, CHARINDEX(' ', REVERSE(OutputText))) FROM #temp
    WHERE PATINDEX('%<DIR>%', OutputText) = 0 -- Make sure no directories
    AND CHARINDEX('/', SUBSTRING(OutputText, 1, 5)) > 0 -- Make sure has a date
    --
    drop table #temp
  • It works! Thanks!

  • thanks for that info Jpipes...I'm going to use it for my requirement of getting filenames and dates...this is better than my previous "parsing mechanism"....

  • no problemo. just a script I thought of this morning...worked great (surprisingly...)

    --

    Cheers

Viewing 9 posts - 1 through 8 (of 8 total)

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