using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; namespace FileWatcher { class Utils { public static string ProgramFilesx86() { if (8 == IntPtr.Size || (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432")))) { return Environment.GetEnvironmentVariable("ProgramFiles(x86)"); } return Environment.GetEnvironmentVariable("ProgramFiles"); } public static string ProgramFilesx64() { return Environment.GetEnvironmentVariable("ProgramW6432"); } /// /// Gets the program default, Program Fils(x86) when program is compiled /// for 32 bit Windows, and Program Files when program is compiled for /// 64bit Windows. /// /// public static string ProgramFiles() { return Environment.GetEnvironmentVariable("ProgramFiles"); } /// /// Returns Windows/System32 or Windows/SysWOW64 depending on your program /// /// public static string SystemDirectory() { return Environment.SystemDirectory; } /// /// Creates a relative path from one file or folder to another. /// /// Contains the directory that defines the start of the relative path. /// Contains the path that defines the endpoint of the relative path. /// Boolean indicating whether to add uri safe escapes to the relative path /// The relative path from the start directory to the end path. /// public static String MakeRelativePath(String fromPath, String toPath) { if (String.IsNullOrEmpty(fromPath)) throw new ArgumentNullException("fromPath"); if (String.IsNullOrEmpty(toPath)) throw new ArgumentNullException("toPath"); // If path doesn't end with '\\' it's assumed to be a file. if (fromPath.EndsWith("\\") == false) { fromPath += "\\"; } Uri fromUri = new Uri(fromPath); Uri toUri = new Uri(toPath); Uri relativeUri = fromUri.MakeRelativeUri(toUri); String relativePath = Uri.UnescapeDataString(relativeUri.ToString()); return relativePath.Replace('/', Path.DirectorySeparatorChar); } } }