यह एक अलग ड्राइव, ड्राइव-संबंधित पथ के लिए पर पथ के लिए और वास्तविक संबंधित पथ के लिए काम करता है। बिल्ली, यह भी काम करता है अगर basePath
वास्तव में पूर्ण नहीं है; यह हमेशा अंतिम फॉलबैक के रूप में वर्तमान कार्यशील निर्देशिका का उपयोग करता है।
public static String GetAbsolutePath(String relativePath, String basePath)
{
if (relativePath == null)
return null;
if (basePath == null)
basePath = Path.GetFullPath("."); // quick way of getting current working directory
else
basePath = GetAbsolutePath(basePath, null); // to be REALLY sure ;)
String path;
// specific for windows paths starting on \ - they need the drive added to them.
// I constructed this piece like this for possible Mono support.
if (!Path.IsPathRooted(relativePath) || "\\".Equals(Path.GetPathRoot(relativePath)))
{
if (relativePath.StartsWith(Path.DirectorySeparatorChar.ToString()))
path = Path.Combine(Path.GetPathRoot(basePath), relativePath.TrimStart(Path.DirectorySeparatorChar));
else
path = Path.Combine(basePath, relativePath);
}
else
path = relativePath;
// resolves any internal "..\" to get the true full path.
return Path.GetFullPath(path);
}
क्या आपका मतलब वर्तमान निर्देशिका का एक सापेक्ष पथ है, दूसरे शब्दों में काम करने वाली निर्देशिका, या .exe के स्थान से संबंधित है? –
दो प्रकार के सापेक्ष पथ हैं। एक "ए \ बी \ सी" फॉर्म के रूप में और एक विशेष आधार का मतलब नहीं है। दूसरे में फॉर्म "। \ ए \ बी" या ".. \ ए \ बी" है; वे वर्तमान कार्य निर्देशिका के सापेक्ष हैं। – MSalters
@ एमिट ढल: वैसे, यह आपकी मदद करने वाले उत्तर (ओं) को स्वीकार करने और उन्हें ऊपर उठाने के लिए अच्छी बात है। –