2

我正在使用 UFT 中的 api 测试通过 FTP 传输文件,如果当我尝试传输文件时本地文件系统上不存在该文件,则会创建一个具有预期原始名称的空文件并通过 ftp 传输。有没有办法返回错误而不仅仅是通过 ftp 复制一个空白文件?我愿意在尝试复制之前使用自定义代码检查文件是否存在,但如果 UFT 在文件不存在时只返回错误会更好。

4

1 回答 1

3

请尝试这个希望它会有所帮助

Set fileSystemObj = createobject("Scripting.FileSystemObject")

'检查给定文件是否存在'

MyFile = "C:\TestFile.txt"

If fileSystemObj.FileExists(MyFile) then

    Msgbox  "File is present" & MyFile

Else

    Msgbox "File does not present" & MyFile

End If

'检查给定文件夹是否存在'

MyFolder = "C:\TestFolder"

If fileSystemObj.FolderExists(MyFolder) Then

    Msgbox  "Folder is present" & MyFolder

Else

    Msgbox "Folder does not present" & MyFolder

End If

'检查给定的驱动器是否存在'

MyDrive ="D:\" 

If fileSystemObj.DriveExists(MyDrive) then 

    Msgbox  "Drive is present" & MyDrive

Else

    Msgbox "Drive does not present" & MyDrive

End If

Set fileSystemObj = Nothing
于 2014-01-21T09:14:12.407 回答