VB中用Filecopy如何判断源文件是否存在?

来源:百度知道 编辑:UC知道 时间:2024/06/16 22:29:17
rpath = "\\cetdata"
dpath = "D:\custom\"
S = Dir(rpath & Text1.Text & "-1.jpg")
Do While S <> ""
FileCopy rpath & S, dpath & S
S = Dir
Loop

然后如何判断源文件是否存在?
S永远<>"" 因为路径是已知了。

谢谢2楼,引用了microsoft scripting runntime 但提示错误编译不为选择性(Optional)

工程里要引用 microsoft scripting runntime

dim fso as new filesystemobject
if fso.fileExists(s)=false then
msgbox "文件不存在"
end if

S = Dir(rpath & Text1.Text & "-1.jpg")
Do While S <> ""

这里不是判断过了?

谁跟你说的"S永远<>"" 因为路径是已知了" ,不要听他瞎掰,S总有="" 的时候!!如果你的rpath这个路径能行,那么你的代码应该没问题!

S <> "" 这不就是判断吗?