Example Code

Check if a Particular File is Open in LabVIEW

产品和环境

本部分要求填写创建该范例所需的产品和操作系统。

如要下载NI软件(包括以下所示产品),请访问ni.com/downloads

    软件

  • LabVIEW

代码和文档

添加附件

Description

This example covers how you check if a particular file is open on your computer in LabVIEW. You also can use this functionality to share a single file between multiple LabVIEW users or an .exe.

How to Use

Most of the File I/O VIs and Functions will give you an error if the file in question is open when the VI executes.

To check if a file is open, you can use a File I/O function, such as Open/Create/Replace File, and evaluate the error code to see if the file is open. For example, Open/Create/Replace File gives error code 5 if you attempt to open a file that is already open.

See the attached VI for an example.

checkiffileopen.png

Related Links

Determine the Active Window in LabVIEW

NI社区“代码范例交流区”(Example Code Exchange)中的代码范例已获得MIT许可

评论
eanegkan
Member
Member
修改时间

Note: The solution described is not guaranteed to work if a 3rd party application has opened the file. This is because some processes may create a temporary copy of the file during open/edit (non-locking), and only open the original version of the file during save. This example is only suitable for applications that use locking mechanisms (i.e. open and reserve the original file).

贡献者