I am trying to re-order strings in an array, based on if they match a string value.
My program is getting a list of files in a directory, and then renaming and moving the files. But I need certain files with a specific name to be renamed after other files. (the files are being renamed with time stamps and are processed in that order).
Example File names:
File-302.txt
File-302-IAT.txt
File-303.txt
File-303-IAT.txt
File-304.txt
File-304-IAT.txt
File-305.txt
File-305-IAT.txt
Basically what I am trying to accomplish, is I would like to move all the files containing "-IAT" to the end if the array, so that when I loop through, the IAT files are processed after their non "IAT" partner file.
Here is my code but theres not much to it:
string[] outFiles = Directory.GetFiles(workingDir);
for (int i = 0; i <= outFiles.Length - 1; i++
{
//code to rename the file in the array
}
C# stackoverflow how to order an array of stringsoutFiles.Where(f => !f.Contains("-IAT")).Concat(outFiles.Where(f => f.Contains("-IAT"))but apart from that you haven't said what order you want the results in - you mention they are processed in order of timestamp?