Test for a directory if it doesn't exist create it and move a file into the directory

I have an old VB6 Program that would take a list of files, loop through the list and move the files into subfolders based upon the first 2 characters in the file name. If a corresponding directory did not exist for the first 2 digits the program would create the directory and then move the files.

I am using Visual Basic 2008 Express

So basically I have a subdirectory named c:\ypm with the following files.

pd123.pdf
ap.123.pdf
ap.224.pdf

I want to end up with a subdirectory c:\ypm as follows:

c:\ypm\pd\123.pdf
c:\ypm\ap.123.pdf
c:\ypm\ap.224.pdf
Rick RudolphAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dshrivallabhCommented:
Direcory di = new Directory("c:\ypm")
Foreach FileInfo fi in di.getfiles()
If Not Directory.Exists(fi.FileName.Substring(0,2))
    Directory.CreatDirectory(fi.FileName.Substring(0,2));
    Directory.SetCurrentDirectory(C:\ypm\fi.FileName.Substring(0,2));
fi.Move(Source,Dest)
Next
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dshrivallabhCommented:
Note: Above code is not tested ..but the actual version of code must be a similar or a bit modified version of the same.
0
Rick RudolphAuthor Commented:
Wasn't a complete solution, but gave me enough information to research a total solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.