Home Forums SQL Server 2005 Development Pulling Filename from Windows directory into table RE: Pulling Filename from Windows directory into table

  • This is a farily simple method:

    declare @files table (cmdout nvarchar(100) )

    insert into @files ( cmdout )

    -- Get filenames excluding directories

    exec master.dbo.xp_cmdshell 'dir C:\ /b /a:-d'

    select cmdout from @files where cmdout is not null order by cmdout

    Results:

    cmdout

    -------------------

    AUTOEXEC.BAT

    BOOT.BAK

    boot.ini

    cmldr

    CONFIG.SYS

    IO.SYS

    license.txt

    MSDOS.SYS

    ntdetect.com

    ntldr

    pagefile.sys