Using xp_ dirtree to List Folders, Subfolders and Files with SQL
You can use an undocumented Extended Stored Procedure named xp_dirtree to list folders, subfolders, and files for a given path. Xp_dirtree has three parameters that need to be supplied: directory?-