Link to home
Start Free TrialLog in
Avatar of tami0587
tami0587

asked on

Check for file existing and create if it doesn't

I'm new to lotusscript.  We need to add to a template to check for a file existing and append to it if it does exist.  If it doesn't exists, it needs to create the folder path and file.  So I have part of it, but can't figure out some of it:

If file doesn't exist


      
If file does exist then
      Dim fileNum As Integer
      Dim fileName As String
      
      fileNum% = Freefile()
      fileName$ = "C:\Program Files\lotus\notes\notes.ini"
      Open fileName$ For Append As fileNum%
      Write #fileNum%, "Line I am going to add"
      Close fileNum%    
ASKER CERTIFIED SOLUTION
Avatar of SysExpert
SysExpert
Flag of Israel image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here are LS-only functions (using Lotus API to create file on disk):

Taken from Domino Document Manager (former DominoDoc) File Cabinet Template.
Function DoesFileExist( filePath As String ) As Integer
	On Error Goto ProcessError
	Const ATTR_DIRECTORY = 16
	
	If Not ( GetFileAttr( filePath ) And ATTR_DIRECTORY ) Then DoesFileExist = True	
 
	Exit Function	
ProcessError:
	DoesFileExist = False
End Function
 
 
Function DoesDirExist( directory As String ) As Integer
	On Error Goto ProcessError
	Const ATTR_DIRECTORY = 16
	
	If Getfileattr( directory$ ) And ATTR_DIRECTORY Then
		DoesDirExist = True
	Else
		DoesDirExist = False
	End If
	
	Exit Function	
ProcessError:
	DoesDirExist = False
End Function
 
 
Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" (Byval lpFileName As String, Byval dwDesiredAccess As Long, Byval dwShareMode As Long, lpSecurityAttributes As Any, Byval dwCreationDisposition As Long, Byval dwFlagsAndAttributes As Long, Byval hTemplateFile As Long) As Long
Declare Function CloseHandle Lib "kernel32"( Byval hObject As Long ) As Long
 
Function CreateFile( FilePath ) As Boolean
	Dim hFile As Long
 
	hFile = CreateFile( FilePath, 0, 1, 0, 3, 0, 0 )
 
	If hfile > 0 Then
		Call CloseHandle( hFile )
		CreateFile = True
	End If
 
End If

Open in new window