Solved

c# determine which files are incoming/outgoing

Posted on 2014-07-17
3
258 Views
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.
FolderFile.jpg
0
Comment
Question by:eli411
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
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
{
      Unknown,
      Incoming,
      Outgoing
}

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)
            {
                  // ...
            }
      }
}
0
 
LVL 2

Author Comment

by:eli411
ID: 40203377
Working good!  Thanks!
0
 
LVL 2

Author Closing Comment

by:eli411
ID: 40203379
Great coding!  Work like magic!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to count occurrences of each item in an array.

930 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

12 Experts available now in Live!

Get 1:1 Help Now