Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net System.IO.File.Exists的存在原因不在于';不要接受if-else语句_Vb.net_Directory_File Copying_System.io.file - Fatal编程技术网

Vb.net System.IO.File.Exists的存在原因不在于';不要接受if-else语句

Vb.net System.IO.File.Exists的存在原因不在于';不要接受if-else语句,vb.net,directory,file-copying,system.io.file,Vb.net,Directory,File Copying,System.io.file,为图像文件运行以下代码时,我遇到了if条件问题: Dim mainFolder As String = "\\Users\No_Image_Available.png" Dim saveDirectory As String = "\\IMAGE\" Dim Filename As String = System.IO.Path.GetFileName(mainFolder) Dim mainSavePath As String = System.IO.Path.

为图像文件运行以下代码时,我遇到了
if
条件问题:

    Dim mainFolder As String = "\\Users\No_Image_Available.png"
    Dim saveDirectory As String = "\\IMAGE\"
    Dim Filename As String = System.IO.Path.GetFileName(mainFolder)
    Dim mainSavePath As String = System.IO.Path.Combine(saveDirectory, Filename)

    If System.IO.File.Exists(mainSavePath) Then
        'do nothing
    Else
        'file doesn't exist
        My.Computer.FileSystem.CopyFile("\\Users\No_Image_Available.png", "\\IMAGES\No_Image_Available.png")

    End If
如果文件不存在,则它将通过
If Not exist
If exist
接受If语句。。。但是,如果文件已经存在,无论是否处于正确的if条件,它都将使用copy参数

为什么呢?这就好像不管怎样,它仍然读取并接受第一个
“不做任何事情”
条件


仅供参考-您看到的路径是假的

问题是它们是服务器目录。我做了有效的修正

Dim Filename = "No_Image_Available.png"
    Dim savePathcopy As String = Server.MapPath("~/IMAGES/")
    Dim pathToCheckCopy As String = savePathcopy + Filename

    'Dim mainSavePath As String = System.IO.Path.Combine(saveDirectory, Filename)
    If (System.IO.File.Exists(pathToCheckCopy)) Then
        ' If System.IO.File.Exists(noImg) = True Then
    Else
        'file doesn't exist
        My.Computer.FileSystem.CopyFile("\\..\Dev\web\WebUsers\...\..\Classified_Ads_V2\No_Image_Available.png", "\\...\Dev\web\WebUsers\...\..\...\IMAGES\No_Image_Available.png")
    End If

与传递给它的路径/文件名相比,问题与
File.Exists()
更相似<代码>你看到的路径是假的为真实答案提供真实代码当引用stackoverflow时,有人得到了。存在为他们工作,这就是我使用它的原因。这是迄今为止我所知道的唯一一个可以使用的@PUROTIX
\\IMAGE\\\Users\No\u IMAGE\u可用。png
这是一个怎样的有效路径?除非在尝试伪造路径名时输入了错误。From:
如果路径为Nothing、无效路径或长度为零的字符串,此方法也会返回false。如果调用方没有足够的权限读取指定的文件,则不会引发任何异常,并且无论路径是否存在,该方法都会返回false。
如果我可以询问,原因可能重复@JoelCoehoornwoops我的坏。完全没有看到链接部分XD好的,我会检查谢谢@乔尔科霍恩