C# parsing txt files IF name format is desired format
Posted
by jakesankey
on Stack Overflow
See other posts from Stack Overflow
or by jakesankey
Published on 2010-05-29T02:11:06Z
Indexed on
2010/05/29
2:12 UTC
Read the original article
Hit count: 426
OK, I have txt files that I am parsing and saving into a sql db. The names are formatted like
R306025COMP_272A4075_20090929_080159.txt
However, there are a select few (out of thousands of files) with names that are formatted differently (particularly files that were generated as tests), example
R306025COMP_SU2_TestBottom_20090915_101441.txt
The reason this causes a problem for me is that I am using Split('_')[1,2,etc] to extract the R number, the 272A4075 portion, and the 20090929 (date) portion. When the application comes across the oddly named files, it fails because it is trying to parse 'TestBottom' as a date and inserts 'SU2' instead of the 272 number.
Basically I want the app to recognize that if the file's name is not formatted like my first example, skip it. Any advice?
© Stack Overflow or respective owner