How can I list .txt files that contain phone numbers in this format (99) 99999-9999 cell and (99 ) 9999-9999 fixed ?
This is the code that I have done so far, you just need to find the string in the format of a phone within the .txt file:
private static void ListarArquivos()
{
try
{
string[] _diretorios = Directory.GetDirectories(@"D:\Arquivos\");
Console.WriteLine("LSITA DE DIRETÓRIOS: ");
Console.WriteLine("");
foreach (string dir in _diretorios)
{
Console.WriteLine(dir);
string[] arrArquivos = Directory.GetFiles(dir, "*.txt");
for (int x=0; x < arrArquivos.Length; x++)
{
if (File.Exists(arrArquivos[x]))
{
using (StreamReader sr = new StreamReader(arrArquivos[x]))
{
string linha;
while ((linha = sr.ReadLine()) != null)
{
Console.WriteLine(linha);
}
}
}
else
{
Console.WriteLine(" O arquivo " + arrArquivos[x] + "não foi localizado !");
}
Console.WriteLine("");
}
}
Console.ReadKey();
}
catch
{
throw;
}
}
Sample txt file, I want NOT to list file2.txt because it does not have a phone number:
Example of file1.txt:
55 (11) 97387-0245
ORGANIZATIONS LTD
55 (11) 99678-3199
55 (11) 97100-0445
MARIA JOSÉ DA SILVA at
Sample .txt file :
JOÃO DA SILVA
ORGANIZATIONS LTD
PADARIA ESTRELA
REMOTE 2 BROTHERS
MARIA JOSÉ DA SILVA at
Example of the .txt file :
(11) 5489-9873
ORGANIZATIONS LTD
PADARA ESTRELA
(11) 5489-5912
MARIA JOSÉ DA SILVA