Say that I set up a symbolic link:
mklink /D C:\\root\\Public\\mytextfile.txt C:\\root\\Public\\myothertextfile.txt
Editor\'s note: O
Maybe someone's interested in a C# method to resolve all directory symlinks in a directory similar to Directory.GetDirectories(). To list Junctions or File symlinks, simply change the regex.
static IEnumerable GetAllSymLinks(string workingdir)
{
Process converter = new Process();
converter.StartInfo = new ProcessStartInfo("cmd", "/c dir /Al") { RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, WorkingDirectory = workingdir };
string output = "";
converter.OutputDataReceived += (sender, e) =>
{
output += e.Data + "\r\n";
};
converter.Start();
converter.BeginOutputReadLine();
converter.WaitForExit();
Regex regex = new Regex(@"\n.*\\s(.*)\s\[(.*)\]\r");
var matches = regex.Matches(output);
foreach (Match match in matches)
{
var name = match.Groups[1].Value.Trim();
var target = match.Groups[2].Value.Trim();
Console.WriteLine("Symlink: " + name + " --> " + target);
yield return new Symlink() { Name = name, Target = target };
}
}
class Symlink
{
public string Name { get; set; }
public string Target { get; set; }
}