I’m trying to find a way to buffer FileNames from a given directory in C#. By this I mean:
Given directory
C:/MyDir
Which contains files:
File1_orig.txt
File1_edited.txt
File2_orig.txt
File2_edited.txt
…
Filen_orig.txt
Filen_edited.txt
I want to store the filenames(not the whole filepath, just the filename, e.g. String[] filename = Filen_orig.txt) into temporary strings and run a simple comparison on them to see if they contain a target string.
I would like to pass the strings into:
while(STILL FILES IN DIRECTORY)
{
string[] exFileName = {BUFFER FILENAME HERE}
string[] words = exFileName.Split('_');
string[] toCompare = "edited";
bool result;
foreach (string word in words)
{
Console.WriteLine(word);
bool result = toCompare.Equals(word, StringComparison.OrdinalIgnoreCase);
if (result)
{
Console.WriteLine("success");
}
}
Console.ReadLine();
To check to see if the file being examined is edited (*_edited.txt) or an original (*_original.txt), and, if the file is edited, further process the file.
Does anyone know how to automate a filepath read?
Thank you very much.
if you want to see if any files contain the _edited bit, you can use:
I’m making a bit of a guess this is what you want because your code isn’t very clear (nor is your description)
Edit: to show all edited files:
Also, must be using “System.Linq”