?
Solved

Moving files into different folders using c#

Posted on 2014-07-23
2
Medium Priority
?
434 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 2000 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

WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

Question has a verified solution.

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

Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
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…
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.

765 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