Follow @PDSAInc June 2007 - Posts - Paul Sheriff's Blog for the Real World

Paul Sheriff's Blog for the Real World

This blog is to share my tips and tricks garnered over 25+ years in the IT industry

Paul's Favorites

June 2007 - Posts

I Love the File/Directory Classes in .NET!

I just had a situation where a potential client gave me a zip file of about 200 files. They wanted us to give them an estimate on how long it would take us to recreate each screen in ASP.NET 2.0. I did not relish the thought of typing in all those file names into an Excel spreadsheet so I could assign hours to each one. So I wrote a simple little utility to grab each file in the folder, and add that file name to a StringBuilder object. I separated each file name with a CRLF. Once I had all of the files in the StringBuilder object, I simply copied the text to the Clipboard. Then I opened up Excel and pasted the contents of the Clipboard into an Excel column. Bingo! I now had all those file names into Excel, ready for me to assign hours to!

C# Code
private void GetFiles()
  System.Text.StringBuilder sb = new System.Text.StringBuilder(1024);
  System.IO.FileInfo fil;

  foreach (string strFile in System.IO.Directory.GetFiles(@"D:\Customers\ASP"))
    fil = new System.IO.FileInfo(strFile);
    sb.Append(fil.Name.Replace(".asp", "") + Environment.NewLine);


Private Sub GetFiles()
  Dim sb As New System.Text.StringBuilder(1024)
  Dim fil As System.IO.FileInfo

  For Each strFile As String In System.IO.Directory.GetFiles("D:\Customer\ASP")
    fil = New System.IO.FileInfo(strFile)
    sb.Append(fil.Name.Replace(".asp", "") & Environment.NewLine)

End Sub

I hope this little tip helps you the next time you have to do something like this!


Posted: Jun 15 2007, 05:53 PM by psheriff | with 4 comment(s)
Filed under:
More Posts