I'm searching for files in my C# program using the following function:
static string[] getFiles(string path, string searchPattern, SearchOption searchOption)
{
string[] searchPatterns = searchPattern.Split('|');
List<string> files = new List<string>();
try
{
foreach (string sp in searchPatterns)
files.AddRange(Directory.GetFiles(path, sp, searchOption));
files.Sort();
} catch (Exception ex){ System.Windows.Forms.MessageBox.Show(ex.Message); }
return files.ToArray();
}
When I search for files I pass in the following code to my function:
var myDocuments = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var files = getFiles(myDocuments, "*", SearchOption.AllDirectories);
Now when I execute the code I get the following error:
For some reason it's searching Documents/My Music instead of C:\Users\Test\Music. The error is occurring on Win7. I presume the cause of the problem is described in the following link (even tho I never upgraded my Windows): Microsoft Document Changes .My aim is to search all files inside the "My Documents" folder. This also includes searching all subdirectories such as My Music, My Pictures etc. Could anyone suggest some different code I can use or a solution to fix this problem?