testing for existence of directory

Hello; I am trying to determine whether a given directory exists. The Exists(dirName) call does not seem to work on my NetWare drive mapping. So, I have resorted to examining the target directory’s parent with the virtual file table. The only problem is that the parent directory may not exist either. How can I trap run-time errors caused by the following call, when ctParentOfTarget is invalid? WITH FileVirtualTable DO BEGIN SETFILTER(Path, ‘%1’, ctParentOfTarget); … Many thanks, Brian.

I don’t know whether an “official” way exists to determine the existance of a directory but you could simply try to create a file in this directory. If you don’t fail it exists :


If file.exists(dirname + 'test.fil') then
   isOk := TRUE
Else
  isOk := file.create (dirname + 'test.fil');

------- With best regards from Switzerland Marcus Fabian

I think you have to put it that way … exists(…) // works file.exists(…) // works not

Actually both works fine. The reason why I qualify “file.” is that some file-related commands (like CLOSE) are ambiguous. A CLOSE in a Form will close the form rather than the file. ------- With best regards from Switzerland Marcus Fabian

If you are looking for a folder and you know the Drive then WITH FileVirtualTable DO BEGIN SETFILTER(Path, ‘%1’, ctParentOfTarget); // Find All Folders in the specified path SETFILTER(“Is a File”,’%1’,FALSE); // Find if Folder Name is Correct SETFILTER(Name,’%1’,TargetDirectory); IF NOT FIND(’-’)THEN ERROR(Directory does not exist); END; David Cox MindSource (UK) Limited Navision Solutions Partner Email: david@mindsource.co.uk Web: www.mindsource.co.uk Edited by - David Cox on 2001 Aug 15 23:55:36

That code only works as long as there is a existing parent-directory. If the parent directory does’nt exist, the FIND will run into a Windows-error that you cannot mask with Navision (and what is Brians problem). Using the virtual tables you first would have to check the existance of the drive and then the existance of every single directory of the path, starting from the root. ---- Hi Marcus, the EXISTS-command is not ambiguous and does not allow any Prefix like “MyFile.EXISTS” :wink: (or do we run different versions?)

Or you might use this:


DirExists(Directory : Text[250]) : Boolean
CLEAR(objFilesystem);
CREATE(objFilesystem);
EXIT(objFilesystem.FolderExists(Directory));

where objFilesystem is type automation of ‘Microsoft Scripting Runtime.FileSystemObject’,’{420B2830-E718-11CF-893D-00A0C9054228}’,‘scrrun.dll’ Soren Nielsen, moderator Integration/Developer NOLUG

Hello Soren and others; My question about directories generated many responses. I opted to shell out to another application to perform the exists() function. I read the exit value to determine whether the directory exists.

quote:


Originally posted by SNielsen: Or you might use this:


DirExists(Directory : Text[250]) : Boolean
CLEAR(objFilesystem);
CREATE(objFilesystem);
EXIT(objFilesystem.FolderExists(Directory));

where objFilesystem is type automation of ‘Microsoft Scripting Runtime.FileSystemObject’,’{420B2830-E718-11CF-893D-00A0C9054228}’,‘scrrun.dll’ Soren Nielsen, moderator Integration/Developer NOLUG


Whauw, guess we visited most of the options for testing for a directory. No doubt, are you seeking a solution: THIS IS THE PLACE TO FIND IT :slight_smile: Soren Nielsen, moderator Integration/Developer NOLUG