Applies To:
  • CitectSCADA 5.xx

Summary:
I am calling FileFind() in a loop to get a number of file and then copy each to another name. Here is the example from the online help:

! Search for all dBase files in the run directory and make a backup
sPath = FileFind("[run]:\*.dbf", 0);
WHILE StrLength(sPath) > 0 DO
    FileSplitPath(sPath, sDrive, sDir, sFile, sExt);
    sBak = FileMakePath(sDrive, sDir, sFile, "BAK");
    FileCopy(sPath, sBak, 0);
    ! Find the next file
    sPath = FileFind("", 0);
END

This only copies one file then ends. What is happening?

 

Solution:
As soon as you call any of the other File functions such as FileCopy() or FileDelete(), FileFind() is reset, so calling FileFind("",0) no longer returns the next file matching the previous search pattern, then the while loop exits and the function finishes.

One solution to this problem is to call FileFind() recursively so it finds all files first then copies or deletes them. Here is an example of a Cicode function called MoveFiles(). In this example, files matching *.DBF in the [DATA] directory are renamed to *.BAK

eg. MoveFiles("[DATA]:\*.DBF")

FUNCTION    MoveFiles(STRING sDirName)
STRING    sPath, sDrive, sDir, sFile, sExt, sBak;
INT    iErr=-1;
sPath = FileFind(sDirName, 0);
IF sPath <> "" THEN
    MoveFiles(""); // Call recursively
    FileSplitPath(sPath, sDrive, sDir, sFile, sExt);
    sBak = FileMakePath(sDrive, sDir, sFile, "BAK");
    iErr = FileCopy(sPath, sBak, 0);
    IF iErr = 0 THEN
    FileDelete(sPath);
    END
END
END

CIT has confirmed this to be a problem in Citect for Windows version 5.x. We are researching this problem and will post new information here as it becomes available.


Keywords:
 

Attachments