Solved

Moving files into different folders using c#

Posted on 2014-07-23
2
431 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

A Change in PHP Behavior with Session Write Short Circuit (http://php.net/manual/en/book.session.php#116217) (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

705 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