# File_WaitForFileToExist

> Checks if a specified file exist, and waits until file exist or until timeout occurs.

Source: https://docs.capaone.com/capainstaller/vb-scripting-library/osd-scripting-library/file-functions-osd/file-waitforfiletoexist/  
Product: CapaInstaller — a separate CapaSystems product; do not apply this page to any other.

[VB Scripting Library](/capainstaller/vb-scripting-library/) > [OSD Scripting Library](/capainstaller/vb-scripting-library/osd-scripting-library/) > [File functions (OSD)](/capainstaller/vb-scripting-library/osd-scripting-library/file-functions-osd/)

### File_WaitForFileToExist(sFile, iWaitMaxMin, iCheckIntervalSec, bMustExist)

Checks if a specified file exist, and waits until file exist or until timeout occurs  
If file is created before timeout occurs, gbValue returns TRUE, otherwise gbValue returns FALSE.

### Arguments

| ARGUMENT          | DESCRIPTION                                                              | TYPE    |
|:------------------|:-------------------------------------------------------------------------|:--------|
| sFile             | The file to check existense/wait for                                     | String  |
| iWaitMaxMin       | Number of minutes to wait for file to be deleted before exiting          | Integer |
| iCheckIntervalSec | Number of seconds between checks                                         | Integer |
| bMustExist        | If TRUE function will fail if timeout is reached and file does not exist | Boolean |

### Return Type

Boolean, TRUE if function completed successfully.

### Example

The following example will create an empty textfile and wait for up to 5 minutes for an external process to delete it.

**VBScript**

```vb
Private Function IncludeScript(sScriptFile)
 '...
End Function

'Begin
  bStatus=True
  If bStatus Then bStatus=IncludeScript("customlib.cis")
  If bStatus Then bStatus=IncludeLibrary("Capalib.cin")
  If bStatus Then bStatus=IncludeLibrary("Osdlib.cin")
  If bStatus Then bStatus=Job_Start("WS", "Script Name", "1.0", "ScriptName.log", "INSTALL")
  If bStatus Then bStatus=OSD_Initialize()
  
  sFile="C:\WaitFile.txt"

  If bStatus Then bStatus=File_WaitForFileToExist(sFile, 5, 10, False)
  If bStatus and NOT gbValue Then bStatus=Dialog_ShowWarning("Timeout occured waiting for file to be created")

  Job_End(bStatus)
'End main

```

### See Also

[Scripting Guidelines](/capainstaller/vb-scripting-library/scripting-guidelines/), [Dialog_ShowWarning](/capainstaller/vb-scripting-library/osd-scripting-library/dialog-functions-osd/dialog-showwarning/) [Constants](/capainstaller/vb-scripting-library/addendum/constants/) [Package Property](/capainstaller/vb-scripting-library/addendum/package-property/) [Variables](/capainstaller/vb-scripting-library/addendum/variables/)
