gpt4 book ai didi

vb.net - 如何检查文件夹中是否已存在文件

转载 作者:行者123 更新时间:2023-12-03 00:58:42 25 4
gpt4 key购买 nike

我正在尝试将一些文件复制到文件夹。我正在使用以下语句来检查源文件是否存在

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

但我不知道如何在复制之前检查文件夹中是否存在文件。请指教。

谢谢并致以最诚挚的问候,富尔坎

最佳答案

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

关于vb.net - 如何检查文件夹中是否已存在文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8352708/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com