DynDeveloper.com

DynDeveloper.com

Sign Up Now! Log In
sgray128 4/2/2012 10:45:47 AM

Loop through files in a folder

* This article, and all our great .NET Development documentation, Is available on the .NET Development menu

In writing Dynamics integrations, I'm frequently asked to read a directory of files and process them somehow. Sometimes they're XML, sometimes text. 

This piece of code is the main loop for that task. It's not ground breaking or brilliant; but it saves me 30-60 minutes of coding to have it ready so that I can copy and paste into an app. 

The basic logic is this:

Create 'done' and 'error' folders to move the files into after processing

Loop

Process the file

Move the file to 'done'

Trap errors

Move the file to 'error

Handle the error 

Version: Unknown or N/A
Section: .NET Development