2011-12-02 13 views
9

いくつかのファイルをフォルダにコピーしようとしています。私は、ソースFIEがファイルが既にフォルダに存在するかどうかを確認する方法

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

が存在するかどうかをチェックするために、次の文を使用しています。しかし、私は、ファイルをコピーする前に、フォルダ内に存在するかどうかを確認する方法を知ってscroll down toパソコンへ転送します。 お知らせください。私が正しく理解していれば

おかげで、よろしく、 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

私は最終的にあなたが何を得ようとしているかを理解していると思います。更新されたコードが意図したものに近いかどうかを教えてください。 –

関連する問題