TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Tamal Banerjee
NA
25
3.3k
How to find which files have errors according to the pattern
Sep 5 2016 11:28 AM
I want to search some regex patterns in files (*.txt) which are inside a folder whose path I'have given in a text box, and the folder contains other sub-folders with txt files in the form 12345-2031-30201\2031\30201\txt\110.txt and if the pattern matches even in one file, then a string is written on a log file which is created inside the folder whose path I've given in the text box and then it moves on to the next regex and so on.
The problem I'm having is the log file writing the matches found in the form
"D:\test\bk\1235-12-3053\230\124\txt\124.txt: Check table link, Check section link, Check figure link "
"D:\test\bk\123561-1-2356\230\129\txt\129.txt: Check section link, Check table link"
However I want it show the macthes found in the below fashion
"Check figure link"==
D:\test\bk\1235-12-3053\230\124\txt\124.txt
D:\test\bk\1235-12-3053\230\131\txt\131.txt
"Check table link"==
D:\test\bk\1235-12-3053\230\124\txt\124.txt
D:\test\bk\1235-12-3053\230\205\txt\205.txt
and so on
Dim
patterns =
New
List(Of
String
()) From {
({
"Check figure link"
,
"(?<!>)(?:figures?|figs?\.) \d+"
}),
({
"Check table link"
,
"(?<!>)(?:tables?|tabs?\.) \d+"
}),
({
"Check section link"
,
"(?<!>)(?:sections?|sect?\.) \d+"
}),
({
"Check space"
,
"</inline>\w+"
})}
Dim
compiledPatterns =
New
Dictionary(Of Regex,
String
)
For
Each
pat
As
String
()
In
patterns
compiledPatterns.Add(
New
Regex(pat(1), RegexOptions.Compiled), pat(0))
Next
Dim
filteredFilenames = From tFile
In
Directory.EnumerateFiles(TextBox1.Text,
"*.txt"
, SearchOption.AllDirectories)
Where tFile
Like
"*\#*\#*\#*\txt\#*.txt"
Dim
output = From tFile
In
filteredFilenames.AsParallel
Let
checks = CheckFile(tFile, compiledPatterns)
Where checks.Any
Select
Path = tFile, Messages = checks
File.WriteAllLines(TextBox1.Text.TrimEnd(
"\"c) & "
\Checklist.log",
From fm
In
output
Select
fm.Path &
": "
&
String
.Join(
", "
, fm.Messages))
MsgBox(
"Process Complete"
)
Can anybode help?
Reply
Answers (
1
)
Garbage Collectors
what are some good and latest books on Android App Dev?