VB Win32 API Programming - Judging whether local or remote files exist

xiaoxiao2021-03-06  107

At noon, a simple and very easy-to-use Win32API function is found on the Fox API (I usually used Win32 API browser), which is used to determine if a local file or remote machine file exists:

1. Private Declare Function Pathfileexists lib "shlwapi.dll" Alias ​​"pathfileexistsa" (Byval Pszpath As String) AS Long

This is a function encapsulated in the shell32.dll system file, which can determine if the local file exists and can determine if the file on the remote computer exists. Function return value is a long-type variable, returns two values ​​0, 1.1 indicates that the file existence (TRUE), 0 indicates that the file does not exist (false). And there is only one parameter SZPATH, which is a string variable. If you want to judge whether the local file is written as: "c: /windows/config/sysbook.txt"), if the file is on the remote computer, its path can be written For (assuming that the other computer IP is 192.168.0.2)

"//192.168.0.2/d $/javatools/somefile.txt", if its computer is called Workstation as

"//Workstation/javatools/somefile.txt", of course, this function can also find web files on the website such as "http://www.microsoft.com/ms.htm"

We can write a simple custom common function to complete this feature, call this API function in the custom function

Public Function GetFileExists (ByVal FileName As String) As Boolean If FileName = "" Then MsgBox "Please enter the file name", vbInformation, "prompt" Exit Function Else GetFileExists = CBool ​​(PathFileExists (FileName)) End IfEnd Function

Add a button on the form interface, and a text box

Private submmand1_click () DIM T as Boolean T = getfileexists ("f: /it/develope/retail/bill/vssver.scc") if t = true kiln text1.text = "This file exists" else text1.text = " This file does not exist "End IFEND SUB

Of course, getfileexists can also be written

"//192.168.0.2/d $/javatools/somefile.txt"

"//workstation/javatools/somefile.txt"

"http://www.microsoft.com/ms.htm"

This function can judge the local or remote folder in addition to the existence of the file.

Whether it exists, I think this is better than using the DIR this VB comes to determine if there is much better, and it is not necessary to call the FileSystemObject component.

转载请注明原文地址:https://www.9cbs.com/read-122997.html

New Post(0)