Home Forums SQL Server 7,2000 T-SQL Counting numbers of files in a directory. RE: Counting numbers of files in a directory.

  • While this will work, note that xp_dirtree is undocumented.

    You can achieve the same result, if you pipe the result from a simple xp_cmdshell DIR... into a table like so:

    create table #temp(

    [name] varchar(100))

    DECLARE @sql varchar(100)

    SET @sql = 'DIR C:\ /b/a-d-s'

    INSERT INTO #temp EXEC master.dbo.xp_cmdshell @sql

    SELECT COUNT(*) FROM #temp WHERE name LIKE 'abc%'

    DROP TABLE #temp

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]