2011-12-02 43 views
9

फ़ोल्डर में पहले से मौजूद है या नहीं, मैं कुछ फ़ाइलों को फ़ोल्डर में कॉपी करने की कोशिश कर रहा हूं। मैं अगर स्रोत छी मौजूदयह जांचने के लिए कि फ़ाइल

 If My.Computer.FileSystem.FileExists(fileToCopy) Then

जाँच करने के लिए निम्न कथन का उपयोग कर रहा लेकिन मुझे पता है कि अगर फाइल को कॉपी करने से पहले फ़ोल्डर में मौजूद है की जाँच करने के donot। कृपया सलाह दें।

धन्यवाद और सादर, Furqan

+0

अगर मैं सही ढंग से समझ आप वास्तव में कैसे मूल पथ से फ़ाइल नाम हटा करें और देखें कि एक ही नाम वाली एक फ़ाइल किसी दूसरे निर्देशिका के अंदर मौजूद करने के लिए पूछ रहे हैं? यही एकमात्र व्याख्या है जो अब मुझे समझ में आता है, क्योंकि आप स्पष्ट रूप से पहले ही जानते हैं कि फ़ाइल कैसे मौजूद है या नहीं। मेरे उदाहरण के रूप में पथों में हेरफेर करने के लिए आप 'system.io.path' कक्षा का उपयोग कर सकते हैं। कृपया हमें बताएं कि क्या वास्तव में इसका मतलब है। –

उत्तर

35
Dim SourcePath as string = "c:\SomeFolder\SomeFileYouWantToCopy.txt" 'This is just an example string and could be anything, it maps to fileToCopy in your code. 
Dim SaveDirectory as string = "c:\DestinationFolder" 

Dim Filename as string = system.io.path.getFileName(SourcePath) 'get the filename of the original file without the directory on it 
Dim SavePath as string = system.io.path.combine(SaveDirectory, Filename) 'combines the saveDirectory and the filename to get a fully qualified path. 

if system.io.file.exists(SavePath) then 
    'The file exists 
else 
    'the file doesn't exist 
end if 
+0

मुझे लगता है कि मैं अंततः समझता हूं कि आप क्या प्राप्त करने की कोशिश कर रहे थे, मुझे बताएं कि अपडेट किया गया कोड आपके इच्छित उद्देश्य के करीब है या नहीं। –

संबंधित मुद्दे