SysDirRead - miss 1 file in the folder list research

pierrick
2022-08-25
2023-12-13
  • pierrick - 2022-08-25

    Hello everyone,

    My programm looking for a file name 'retain' in a folder. To do it I'm using SysDirOpen to open folder directory then I'm using SysDirRead to listing files.
    But at everytime, SysDirRead miss the first file in the directory. I don't know why.
    Have you any idea ?

    Below the part of my code :

    VAR_GLOBAL
        stDirHandle : SysDir.RTS_IEC_HANDLE;            (* Folder path result *)
        stResultRead: SysDir.RTS_IEC_RESULT;            (* Stock Runtime error code of SysDirRead *)
        stmaxNumbrebyteDir: DINT := 200;                (* Max byte number for a file name in a file folder *)
        pDirResult: POINTER TO SysDir.RTS_IEC_RESULT;   (* Openning Folder result *)
        DirReadResult: STRING;                          (* Stock SysDirRead result *)
        config_list  : ARRAY[0..19] OF STRING(30);      (* Array filling by standard retain config *)
    END_VAR
    
    (* Opening config directory *)
    stDirHandle := sysDirOpen(szDir := retainConfigFile.PathFolderFile, '', 0, 0, pResult := pDirResult);
    
    (*Open checking *)
    IF pDirResult = CmpErrors.Errors.ERR_OK THEN 
        (* Looking for retain file in config folder and saving them in config_list while there is file's to read *)
            WHILE sysDirRead(hDir := stDirHandle, szDirEntry := DirReadResult, diMaxDirEntry := stmaxNumbrebyteDir, 0) <> CmpErrors.Errors.ERR_END_OF_OBJECT DO
                IF FIND(DirReadResult,'retain') = 1 THEN
                    config_list[_i] := DirReadResult;
                END_IF
            END_WHILE
    END_IF
    

    For example, in my folder I have these files :
    retaina_CHIP_T rev02.txt
    retaina_CHIP_A rev01.txt

    And szDirEntry will return in 3 loops :
    '.'
    'retainaCHIPA rev01.txt'
    '..'

    thanks in advance for your help
    Pierrick

     
  • dagi89 - 2023-01-05

    I have the same problem and no way to let it work.

    Did you find a solution?

    Thansk,

    Dagi89

     
  • pierrick - 2023-01-06

    Hello dagi89,

    The unique solution I have found to continue my project is to add a fake file which is not read by SysDirRead.

     

Log in to post a comment.