如何检查文件是否存在? [英] how can I check if a file exists?

查看:28
本文介绍了如何检查文件是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查一个文件是否存在,如果存在,我想打开它并阅读第一行,

I want to check to see if a file exists and if it does, I want to open it and read the 1st line,

如果文件不存在或者文件没有​​内容,那么我想静默失败而不让任何人知道发生了错误.

If the file doesn't exist or if the file has no contents then I want to fail silently without letting anyone know that an error occurred.

推荐答案

从这个开始:

Set fso = CreateObject("Scripting.FileSystemObject")
If (fso.FileExists(path)) Then
   msg = path & " exists."
Else
   msg = path & " doesn't exist."
End If

取自文档.

这篇关于如何检查文件是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆