Solved

Moving files into different folders using c#

Posted on 2014-07-23
2
416 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
Comment Utility
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
Comment Utility
Thanks for the reference!  Working good!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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…
Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now