?
Solved

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

Posted on 2010-04-04
3
Medium Priority
?
311 Views
Last Modified: 2013-11-27
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
0
Comment
Question by:Rick Rudolph
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
dshrivallabh earned 1500 total points
ID: 29760538
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
 
LVL 4

Expert Comment

by:dshrivallabh
ID: 29760616
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
 

Author Closing Comment

by:Rick Rudolph
ID: 31877307
Wasn't a complete solution, but gave me enough information to research a total solution.
0

Featured Post

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Question has a verified solution.

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

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …

599 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