OpenNTF.org - MAC solution for file existing
My Links (Not logged in)
Code Bin Search
 
Hosted by Prominic.NET
Rate This Code
5 - brilliant stuff
4 - very nice
3 - average
2 - needs work
1 - bad
   OpenNTF Code Bin
About This Code
Brief Description:
MAC solution for file existing with DIR function issue 
Rating:
Not Rated Yet 
Contributor:
Jim Romaine 
Category:
Lotusscript, Other 
Type:
Example Code 
Notes Version:
R6.x 
Last Modified:
15 May 2006 
OpenNTF Disclaimer

All of the program code and information presented in the OpenNTF.org Code Bin are provided "as-is", and should be used at your own risk. OpenNTF.org make no express or implied warranty about anything in the Code Bin, and OpenNTF.org will not be responsible or liable for any damage caused by the use or misuse of anything from this site. OpenNTF.org makes no guarantees about anything. Please thoroughly test all of the knowledge and code you find here before you attempt to use them in your production environment.

Code / Description
Originally posted here for review:

http://www.openntf.org/mainbar.nsf/WebBoardSub?OpenView&RestrictToCategory=F7365F1921FD2DA586257165004EC28F&Count=30&ExpandSection=0

I wanted to include in the code area for easier searching.
For use on MAC ( R6.5.5 Notes MAC OS X , sorry if I have the naming convention wrong I am not a MAC user ) that has additional checking on Windows platform.

There was an issue discovered when attempting to locate files on a MAC using the DIR funciton in Lotusscript. The error returned was "Path not found" even when the file existed. Additional investigations indicated to verify read/write security which was also verified ( by manually saving the file to various tested locations). My approach to solve this issue is to try to open the file for input and if it fails the assumption is that it would be due to the file not existing ( on MAC specifically as other OS will fail on file locking).

This solution is only to address determining if a file exists and not designed for the alternative use of the DIR funciton to loop through all files in a given directory.

Hope this helps anyone with a similiar issue ( or if a better solution is known, please comment )
Thanks,
Jim

Usage / Example
PS the error routine uses Julian Robichaux´s excellent Open Log template at http://www.nsftools.com.
CODE TO FOLLOW:
%REM
/**
********* FileExists
********* Created 05.02.06 Modified 05.04.06
*
*
*PURPOSE
*This routine was created to determine if a file exists by the same name in the directory that a user
*would be attempting to save an attachment. This is called mainly from routines that are
*about to save an attachment from a notes document to a local system.
*
*
*SPECIAL NOTES
*When initially attempted on a MAC the simple DIR function failed regardless if the file existed or not
*investigations into the issue had others find out that DIR on MAC was only successful for folders
*not individual files. In some operating systems failure to open can be caused by file locking, so this
*routine is initially limited to MACs for the first have of the testing. The NotesUIWorkspace method
*"SAVEFILEDIALOG" is easiest way to have user pick the file and get the correct file structure
*
*
*HISTORY
*05.02.06 Jim Romaine created this version
*05.04.06 JRR checking if added attribute addresses issue for MAC
* trying to open file for input to test existence on mac
*
*@author Jim Romaine
*@since 05.04.06
*@version 1.0123
*@param strFN String the full file path, OS specific ( ie "/" , "\", ":" file separators ) of the file
* to check existence of
*@return Boolean true if the file is found
*
*/
%END REM
Function FileExists ( strFN As String ) As Boolean
On Error Goto ErrorHandler

Dim strTmp As String
Dim fileNum As Integer

FileExists = False
strTmp = ""
´ due to potential fail of open file for file locking reasons on some os and other
´ yet to be discovered errors for file open this is limited to MAC as DIR works as needed in Windows
If isDefined("MAC") Then
´ try to open the file for input if an error is raised then the file doesn´t exist and is ok to create
fileNum% = Freefile()
Open strFN For Input As fileNum%
´ if we get here without erroring then the file exists
Close fileNum%
FileExists = True
Else
strTmp = Dir$( strFN, 0 )
If strTmp <> "" Then
FileExists = True
End If
End If

ResumeMACERROR:
´skip previous statement so FileExists returns false
ExitSubRoutine:
Exit Function
ErrorHandler:
´the initial error trapped on MAC was #101 "unable to open file"
´while it is documented that MAC should allow files to be opened under most circumstances
´the one ( and only ?) time it will absolutely fail is if the file does not exist which is what we want
´to test for
Call LogError
Resume ResumeMACERROR ´ ignoring errors for mac when path not found
End Function
 Comments

No documents found

 Add your comment!