मैं C # में दो रास्तों से कैसे जुड़ूं?


100

मैं C # में दो फ़ाइल पथ कैसे शामिल करूं?


7
दो रास्ते से जुड़ने का क्या मतलब है? दो भागों या दो अलग-अलग फ़ाइलों में फ़ाइल पथ? यदि दो भागों में फ़ाइल का पथ का उपयोग करें System.IO.Path.Combine (path1, path2)। अधिक जानकारी [ msdn.microsoft.com/en-us/library/system.io.path.combine.aspx]
— TheVillageIdiot

जवाबों:


158

आपको नीचे दिए उदाहरण में Path.Combine () का उपयोग करना होगा :

string basePath = @"c:\temp";
string filePath = "test.txt";
string combinedPath = Path.Combine(basePath, filePath); 
// produces c:\temp\test.txt

14
यह ध्यान देने योग्य है कि यदि "filePath" में एक पूर्ण पथ है, तो Path.Combine केवल "filePath" देता है। string basePath = @"c:\temp\"; string filePath = @"c:\dev\test.txt"; /* for whatever reason */ string combined = Path.Combine(basePath, filePath);@ "c: \ dev \ test.txt" का उत्पादन करता है
— Jan 'splite' K.

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.