Applies To:
  • CitectSCADA 5.xx, 6.xx
  • CitectHMI 5.xx, 6.xx

Most commands in Citect that create files will fail if the specified folder does not exist. How do you create folders from Cicode?

It is possible to execute the DOS MD (make directory) command using the Cicode Exec() function (Q1028, Q2138). However, the Windows API offers a DLL function that will do this without opening a DOS window. It also has the advantage that it will create multiple nested folders if necessary. For example, with the CreatePath code below, the following command will create a Reports, Daily, Section 1, and Processing folder if they do not already exist:
CreatePath("c:\Reports\Daily\Section 1\Processing");

Use the following code in CitectSCADA 6.10 and later. In earlier versions of Citect, replace the DLLCallEx() function with DLLCall(). The MakeSureDirectoryPathExists function is not available on Windows 95/98/NT.

INT mhCreatePath = -1;
// Creates all folders necessary for the specified path to be valid
// If the path includes a filename, the filename is ignored.
// Path substitution may be used.
// Returns TRUE if successful
CreatePath(STRING sPath)
sPath = PathToStr(sPath);
IF mhCreatePath = -1 THEN
mhCreatePath = DLLOpen("dbghelp.dll", "MakeSureDirectoryPathExists", "AC");
RETURN DLLCallEx(mhCreatePath, sPath);

directory, MKDIR