Solved

c# determine which files are incoming/outgoing

Posted on 2014-07-17
3
264 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
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…
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…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

830 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