devxlogo

Do You Have Access To A Drive Without Opening A File On That Drive

Do You Have Access To A Drive Without Opening A File On That Drive

Assume that you have the full path name of a file, and you need to beable to tell if the drive is writeable (that is, if it is a CD-ROM or anetwork drive to which you have write access). Checking the attributesof the file is not enough, because the file may not be marked read-only,but the drive may be a read-only drive. However, if you open the file forWrite or Append inside VB, it will reset the file’s date stamp, which youdon’t want.To determine if a file is writeable without writing to it, get the attributesof the file with GetAttr, and then attempt to change them with SetAttr.This operation will fail if you do not have write permission on the drive.On the other hand, if you are worried about a file being locked for writing(like an EXE is while it is running under Windows), you should use theOpenFile() API call with the OF_WRITE switch. This call will generate anerror if the file cannot be opened for writing, but will not change thetime stamp if you simply close it right away.

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist