Dir([pathname],[Attributes as VbFileAttribute=vbNormal]) As String
解釋: pathname:文件的絕對路徑;
Attributes:文件的屬性。
“[]”內爲可選項。dir(file)=""表示文件不存在,dir(file)<>""表示文件存在。
例如判斷c:wpswinwps.exe是否存在,如存在,就調用它,可用下列語句:
if dir("c:wpswinwps.exe")<>"" then
shell "c:wpswinwps.exe"
end if
但如果判斷的文件是隱藏文件,上面的語句則無法判斷出來,這時就需要加上後面的可選項目,例如
判斷C盤根目錄下是否有隱藏文件command.com,就用下面的源代碼:
if dir("c:command.com,vbhidden")<>"" then
msgbox"Found c:command.com"
end if
判斷文件夾是否存在,可用下列語句:
dir(文件夾路徑, vbDirectory) <>""
例如,要判斷文件夾c:aaa是否正在,則代碼如下:
if Dir("c:aaa", vbDirectory) <>"" then
msgbox"文件夾:c:aaa 存在!"
end if