Take the 2-minute tour ×

I am looking for the best method for a windows computer to grab a directory listing, output the result to a formatted text file I can then use to make a SQL update.

Directories are formated:






What I was considering is a output file containing:


My limitations are that I am not on, nor do I have access to a Linux computer for nifty tools such as cat. So I have decided C# and the .Net framework are my best bet to accomplish this. I believe Phython or Perl would do just as well but I have yet to learn either language.

Any suggestions on how to write such a program or other ideas on how to tackle this are most welcome.

To be clear, my intentions are to get a directory listing with files all ending in '.jpg' outputted to a text file in a way that I can manipulate to create an SQL INSERT into a database. Programming something to accomplish this would take considerably less time than making each entry through a Content Management system for this and future tasks. The directories are easily in the thousands.

Thank you for your time.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

DirectoryInfo should give you what you need -- http://msdn.microsoft.com/en-us/library/system.io.directoryinfo.aspx

share|improve this answer
Beautiful work, got the listing of files with extension *.jpg to an array complete with file path. Now to write that to a comma seperated file which i can work with. –  enigmaspade May 24 '11 at 21:10
Awesome... glad that helped! –  Jemes May 25 '11 at 1:13
add comment

You could use Linq-to-FileSystem to query a directory, listing all the folders, files and sub-folders. The article below demonstrates the API:


share|improve this answer
After some reading I think .net has what I need to read directories and files built-in. My current issue now is figuring out how best to write and append the results to a file. And how exactly I plan to read that file with SQL to make an Insert. For something so simple in Linux and MySQL this is proving to be such a pain. Can't stand Windows, but it is a necessary evil for my current job. So back to figuring out C# and MSSql. –  enigmaspade May 24 '11 at 21:01
add comment

Your Answer


