SQL xp_cmdshell to get file paths

Posted on 2012-09-17
Medium Priority
Last Modified: 2012-09-18
Hi all,

This is the simplest form of xp_cmdshell that I have seen. How would I produce a table that shows the file's paths in their subfolders?

declare @files table (ID int IDENTITY, FileName varchar(100))
insert into @files execute xp_cmdshell 'dir d:\import\ /b'
select * from @files

Question by:PharmAll

Accepted Solution

keyu earned 2000 total points
ID: 38408427

Author Closing Comment

ID: 38411781
Absolutely brilliant - thank you very much!

And what great article - I will bookmark that one.

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question