Execute the following T-SQL example scripts in Microsoft SQL Server Management Studio Query Editor to list all files and all directories in a directory using xp_cmdshell extended system stored procedure.
Warning article: What are the security risks using cmdexec?
-- List all files in a directory - T-SQL parse string for date and filename
-- Microsoft SQL Server command shell statement - xp_cmdshell