Created On:  16 February 2012

Executing the following code on a Windows Server 2008 R2 German OS:

[-] testcase myDirExists() appstate none
    [ ]
    [ ] STRING myDirGm
    [ ] myDirGm = "C:\Programme (x86)\Silk"
    [ ]
    [-] if Sys_DirExists(myDirGm)
       [ ] print(" The directory C:\Programme (x86)\Silk exists ")
    [-] else
       [ ] print(" The directory does not exist ")

Will return:  " The directory does not exist " -  even though the directory “C:\Programme (x86)\Silk” does exist

As you can see the directory “C:\Programme (x86)\Silk” does exist:



However if you click on the Windows Explorer bar, the directory changes from “C:\Programme (x86)\Silk” to “C:\Program Files (x86)”



The reason why this is, is the correct Object Name of the directory "C:\Programme (x86)\Silk" is actually called “C:\Program Files (x86)”; therefore hence why the function Sys_DirExists fails to find the object.  This can be confirmed by right clicking on SILK folder, selecting properties and the “Security | Sicherheit” tab; which confirms that the “Object Name” = “C:\Program Files (x86)\Silk”

Therefore  in this instance Sys_DirExists()is working as expected.

Therefore to manage the differences of different platforms it is good to use a generic environment variable that hides the Operating System differences. As using the environment variable %ProgramFiles% you will return the correct path name on any Windows System regardless of how the program files is called on that system. 

As an example, the following testcase below uses the environment variable “ProgramFiles” instead of a hard coded string to represent the directory; which means that the code will correctly check the existence of the “Program Files” directory on any Windows Platform


[-] testcase myDirExists() appstate none
    [ ]
    [ ] STRING myDirGeneric
    [ ] myDirGeneric = Sys_GetEnv("ProgramFiles")
    [ ]
    [ ] verifyDirExists(myDirGeneric)
    [ ] 
[-] void verifyDirExists(String myDir)
    [-] if Sys_DirExists(myDir)
      [ ] print(" The directory {myDir} exists ")
    [-] else
      [ ] print(" The directory does not exist ")