Solved

Moving files into different folders using c#

Posted on 2014-07-23
2
421 Views
Last Modified: 2014-07-24
I am trying to write code to move 7000 files from one folder into different folders based on the years.  Following are some examples of the files name in the centralized location:

07032014FundsIncomingMessages.txt
01022014FundsIncomingMessages.txt
06102010FundsOutgoingMessages.txt
06102011FundsOutgoingMessages.txt
...

so the code will basically move the "07032014FundsIncomingMessages.txt" and "01022014FundsIncomingMessages.txt" into a folder "2014".  The "06102010FundsOutgoingMessages.txt" will move into a folder "2010".  The "06102011FundsOutgoingMessages.txt" will move into a folder "2011".

This is going to be written on c#!  Thanks!
0
Comment
Question by:eli411
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 40216402
step 1: list the files from a folder (Directory):
here is the technical reference with code sample:
http://msdn.microsoft.com/en-us/library/07wt70x2%28v=vs.110%29.aspx

step 2: for each of the files, you extract the "year" information, which is a plain string.SubString function:
http://msdn.microsoft.com/en-us/library/system.string.substring%28v=vs.110%29.aspx
assuming that its always characters 5-8, you use filename.SubString(4,4)

step 3: move the file:
here is the technical reference with code sample:
http://msdn.microsoft.com/en-us/library/system.io.file.move%28v=vs.110%29.aspx

what else would you need (apart from someone writing you the full code, which is not the objective of EE)?
0
 
LVL 2

Author Closing Comment

by:eli411
ID: 40217096
Thanks for the reference!  Working good!
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

786 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