Click here to Skip to main content
14,739,263 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have the following Enum that reads a text file accordingly. What I need to do with the file is parse the date from the textfile name so I can check records for it through my database. How do I set the each file to read through the date?

What I have tried:

public enum FileType
        {
            Customer, Account, Transaction
        }


public FileTypeInfo(FileType type, int ssnesPos, int idPos, string name)
               : this()
           {
               Type = type;
               SSNesPosition = ssnesPos;
               CustIDPosition = idPos;
               Name = name;
           }


FileInfo = new Dictionary<FileType, FileTypeInfo>();

            FileInfo[FileType.Customer] = new FileTypeInfo(FileType.Customer, 3, -1, "Customers");
            FileInfo[FileType.Account] = new FileTypeInfo(FileType.Account, -1, 1, "Accounts");
            FileInfo[FileType.Transaction] = new FileTypeInfo(FileType.Transaction, -1, 1, "Transactions");
string names = "";
            foreach (var f in FileInfo)
            {
                names += f.Value.Name + ", ";
            }
            names = names.Remove(names.Length - 2);
            Log.Info("Found configuration information for " + FileInfo.Count + " types of file: " + names + ".");
        }
Posted
Updated 1-Feb-17 9:18am
v2
Comments
[no name] 1-Feb-17 13:44pm
   
I have read this 5 or more times and I have absolutely no idea what it is that you are asking.
SmartDeveloping 1-Feb-17 13:57pm
   
I have a textfile name, currently I can read which type of file it is. "Customer" or Accounts but I need to also parse its date as well which is different everyday.
[no name] 1-Feb-17 14:10pm
   
Okay so that appears to have nothing at all to do with anything in your posting. Johns solution is probably what you want.
SmartDeveloping 1-Feb-17 14:12pm
   
No, because I am reading a while. The process above basically checks what type of file I am reading before I can process through.
[no name] 1-Feb-17 14:14pm
   
Okay then you need to tell us what DO you want. We have no idea what date you are even talking about. The only thing we DO know for sure is that an enum has nothing to do with dates.
SmartDeveloping 1-Feb-17 14:15pm
   
Correct, What I need is to Parse through a textfile name and find out the date of the textfile. Currently I only know which type of file it is through the Enum.
[no name] 1-Feb-17 14:41pm
   
Okay..... either you do not know how to ask a question, or you think we have some mystical powers that pull information out of the air. Get the string of the date from the filename then use the DateTime.Parse or ParseExact methods to turn the string into an actual DateTime.
#realJSOP 1-Feb-17 14:03pm
   
Your question is VERY poorly worded, and having an enum has NOTHING to do with what you appear to be asking.
SmartDeveloping 1-Feb-17 14:08pm
   
Sorry maybe I am having trouble explaining. My current enum process runs through and gives me what type of file I am processing, but now I need to process the date as well to match database records.
#realJSOP 2-Feb-17 13:10pm
   
The filename has NOTHING to do with the enum as far as parsing dates is concerned.
Maciej Los 1-Feb-17 16:57pm
   
You mean you want to get date from the name of file. For example, from: "blablabla_20170201_config.txt" you want to get 20170201?

1 solution

If you need the date the file was last written:

DateTime fileTime = File.GetLastWriteTime(filename);
   
Comments
Maciej Los 1-Feb-17 16:53pm
   
SmartDeveloping wrote: "What I need to do with the file is parse the date from the textfile name". So, i think your solution does not correspond to OP needs.
#realJSOP 2-Feb-17 13:09pm
   
Well, he didn't give us an example of the filename, so how are we supposed to come to that conclusion?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900