Solved

Moving files into different folders using c#

Posted on 2014-07-23
2
425 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
pdf file 7 95
Please explain purpose of GZIP 4 59
Graph API & MS Apps 1 56
Why use this lambda? 12 63
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
These days, all we hear about hacktivists took down so and so websites and retrieved thousands of user’s data. One of the techniques to get unauthorized access to database is by performing SQL injection. This article is quite lengthy which gives bas…
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 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.

749 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