Click here to Skip to main content
15,890,512 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:

C#
public enum FileType
        {
            Customer, Account, Transaction
        }


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


C#
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 8: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.

1 solution

If you need the date the file was last written:

C#
DateTime fileTime = File.GetLastWriteTime(filename);
 
Share this answer
 
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