c# determine which files are incoming/outgoing

Posted on 2014-07-17
Last Modified: 2014-07-17
I had a project to convert existing folders files into different category folder!  Attached is the sample files (see attachment).  I wanted to identify which file is Incoming and which is Outgoing.  The naming on the files can be identify from the name "Incoming" and "Outgoing".  Now how can I code it in c# to identify that?  I had like thousands of files to convert so it would make senses to write code to do the job!  

The foldername is 2012 which contains all the files in it.
Question by:eli411
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

Accepted Solution

Barry Smith earned 500 total points
ID: 40202961
You just need to test the text of each file's name for whether it contains the text "Incoming" or "Outgoing."

Here's a way to do this:

public enum IODirection

public static IODirection WhichDirection(string filename)
      IODirection result = IODirection.Unknown;

      if (filename.Contains("Incoming"))
            result = IODirection.Incoming;
      else if (filename.Contains("Outgoing"))
            result = IODirection.Outgoing;

      return result;

public void Example()
      string folderPath = "C:\\ExampleFolder";
      foreach (string filename in System.IO.Directory.GetFiles(folderPath))
            if (WhichDirection(filename) == IODirection.Incoming)
                  // ...
            else if (WhichDirection(filename) == IODirection.Outgoing)
                  // ...

Author Comment

ID: 40203377
Working good!  Thanks!

Author Closing Comment

ID: 40203379
Great coding!  Work like magic!

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

728 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