Tip: Create a directory

The folowing routine solves the problem: Does a directory exist? If not, create it. Var SearchDirectory : Text200 rtFileSystem : Automation ‘Microsoft Scripting Runtime’.FileSystemObject Begin SearchDirectory := ‘C:\Temp\testdirectory’; CREATE(rtFileSystem); IF NOT rtFileSystem.FolderExists(SearchDirectory) THEN rtFileSystem.CreateFolder(SearchDirectory); end; Marcus Marcus Fabian phone: +41 79 4397872 m.fabian@thenet.ch

There’s an even simpler way to create a directory: This example uses an Integer variable called “ShellNumber” and a text variable called “DirectoryPath.” DirectoryPath should contain the complete name of the directory you want to create, including the disk drive letter and the colon and back slash after the disk drive letter. You can create a directory with one line of code: ShellNumber := (STRSUBSTNO(’%1 /c MkDir %2’, environ(‘COMSPEC’),DirectoryPath); The purpose of ShellNumber is to make sure that the NF client closes down the command processor. You can leave it off, but you will be wasting memory-- and if you run the SHELL command many times, your machine will get slower and slowwer and slowwwer and eventually it will grind to a halt. The ENVIRON(‘COMSPEC’) constant points to a standard Windows environment variable which contains the filespec for the DOS command processor. The ‘/c’ is an argument which tells the command processor to run the DOS command specified by the rest of the command line. MkDir is the DOS make directory command. If the DirectoryPath already exists, the MkDir command will return an error message— but Navision ignores the error message. You will see the words “Directory already exists” in the DOS window for an instant before Navision automtically closes the DOS window. --Tim Horrigan Tim.Horrigan@emsolution.com ------- Tim Horrigan

There is one minor bug with my approach: it only creates one directory at a time. That is: If you want to create (let’s say) “C:\level1\level2\level3”, my approach works only if “C:\level1” and “C:\level1\level2” already exist. ------- Tim Horrigan