I am trying to recurse through a SpecialFolder (Environment.SpecialFolder.StartMenu and Environment.SpecialFolder.DesktopDirectory) in my application and it works for English installations.
However I am having the following issues on non-English installations:
When I use the non localized paths I get UnauthorizedAccessException for any subfolders I try to access
If I localize the result of Environment.GetFolderPath and attempt to get a listing of sub directories I get a DirectoryNotFoundException on the localized path. An example of the localized path:
Original -> C:\Users\tony\AppData\Roaming\Microsoft\Windows\Start Menu
Localized -> C:\Utilisateurs\tony\AppData\Roaming\Microsoft\Windows\Menu Démarrer
I use Environment.GetFolderPath to get the directory, and then search through the locations for a specific file with the following method:
private static IEnumerable<string> LocateAppShortcut(string dir)
{
foreach (string directory in Directory.GetDirectories(dir))
{
foreach (string file in Directory.GetFiles(directory, "MyApp.appref-ms"))
{
yield return file;
}
foreach (string file in LocateAppShortcut(directory))
{
yield return file;
}
}
}
I am looking for a method that will allow me to reliably recurse through a directory path returned by Environment.GetFolderPath when given a starting point where the starting directory can contain reparse and/or junction points.
AFAIK, localized system folder are just aliases, if you run a cmd and dir your main drive, you'll see that the "users" folder is called, well, "Users", independently of your system language, so check your paths. I've confirmed this, as my system is configured in Spanish:
C:\>dir
El volumen de la unidad C es ----------
El número de serie del volumen es: ---------
Directorio de C:\
10/12/2013 12:26 <DIR> inetpub
06/10/2013 17:51 <DIR> Intel
18/02/2014 14:34 <DIR> Mis lugares Web
03/12/2013 17:52 <DIR> NVIDIA
22/08/2013 17:22 <DIR> PerfLogs
24/02/2014 14:35 <DIR> Program Files
12/06/2014 09:18 <DIR> Program Files (x86)
18/09/2013 20:41 <DIR> Toshiba
10/12/2013 12:42 <DIR> Users
11/04/2014 15:08 <DIR> Windows
0 archivos 0 bytes
11 dirs 664.620.318.720 bytes libres
C:\>
I dno't have enough data to diagnose your problem, but you could test your function by getting random paths from a FolderBrowserDialog and passing them to debug your function, see which of them work and which doesn't, see if it's the main call which is failing or is it one of the recursions...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With