IF ready_to_create AND NOT xCreateDone THEN
( create the complete file pathes)
( The file names can be adapted )
sFirstFileName := CONCAT('/', SelectName);//'/firstTest.csv';
sRenameFileName := CONCAT('/', newFileName);//'/rename existing .csv';
( Delete existing files )
IF xStart_delete_file THEN
( create the complete file pathes)
( The file names can be adapted )
sFirstFileName := CONCAT('/', SelectName);//'/firstTest.csv';
In the past I have added something like the following to a loop, usually in a case statement. This is back in SP 4 Patch 2 so there might be an easier way to do it now.
VAR
   sDirectoryList : FILE.DirList;
   sFileEntry : FILE.FILE_DIR_ENTRY; //Properties of entry in directory
   sDirHandle : CAA.HANDLE; //Open directory handle
   RunState : USINT;END_VARCASERunStateOF1: (*Findandstoreallfilesthatcanbeloaded*)
   sDirectoryList(xExecute:=TRUE,hDir:=sDirHandle,deDirEntry=>sFileEntry);
   IFsDirectoryList.xDoneTHEN
     IFNOTsFileEntry.xDirectoryTHEN
        //Whattodoiftheentryisnotadirectory
     ELSE
        //Whattodoiftheentryisadirectory
     END_IF
     sDirectoryList(xExecute:=FALSE); //Set directory list to false so that on next cycle it will look for the next entry in the directory.
   ELSIFsDirectoryList.eError=FILE.ERROR.NO_MORE_ENTRIESOR(sDirectoryList.xErrorANDsDirectoryList.eError<>FILE.ERROR.NO_MORE_ENTRIES)THEN
     //Changestateorendloop
     RunState :=100;
   END_IFELSE
   //EndofcheckEND_CASE
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks for your reply ..!
Your example is not work for me.. May be my syntax is not correct.. the program stack here <<sdirectorylist.xdone>></sdirectorylist.xdone>
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I notice that your udiDirHandle is empty so something is not setup correctly there. I haven't played around much with the way you are doing it but here is a working example. This example will count the number of files and directories in a specific location defined by "sDirectory". In the below example I was not getting the directory '.' to show up but it would count '..' as the first directory. If you have more time and care you can probably look into it. There are a lot of optimizations you can do do speed the search up but this will get you running.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
In my program I can create directory, create delete and rename csv files.
I don't know how can I read all the csv file names and insert it in a list?
Here is my program
VAR
sDirName : STRING ;
sDirName_tmp : STRING := 'StirrupDB';
sFirstFileName : STRING;
sRenameFileName : STRING;
newFileName : STRING;
Name : STRING :='config.csv';
END_VAR
xStartCreate_trig_r(CLK:= xStart_new_file);
xStartRename_trig_r(CLK:=xStart_rename_file);
xStartDelete_trig_r(CLK:=xStart_delete_file);
IF xStartCreate_trig_r.Q THEN
init := FALSE;
name_exist := FALSE;
xError := FALSE;
xCreateDone := FALSE;
ready_to_create := TRUE;
SelectName := Name;
END_IF
IF xStartDelete_trig_r.Q THEN
xDeleteDone := FALSE;
SelectName := Name;
END_IF
IF xStartRename_trig_r.Q THEN
init := FALSE;
name_exist := FALSE;
xError := FALSE;
xDeleteDone := FALSE;
xCreateDone := FALSE;
ready_to_create := TRUE;
newFileName := Name;
END_IF
IF ready_to_create AND NOT xCreateDone THEN
( create the complete file pathes)
( The file names can be adapted )
sFirstFileName := CONCAT('/', SelectName);//'/firstTest.csv';
sRenameFileName := CONCAT('/', newFileName);//'/rename existing .csv';
END_IF
( Delete existing files )
IF xStart_delete_file THEN
( create the complete file pathes)
( The file names can be adapted )
sFirstFileName := CONCAT('/', SelectName);//'/firstTest.csv';
END_IF
In the past I have added something like the following to a loop, usually in a case statement. This is back in SP 4 Patch 2 so there might be an easier way to do it now.
Thanks for your reply ..!
Your example is not work for me.. May be my syntax is not correct.. the program stack here <<sdirectorylist.xdone>></sdirectorylist.xdone>
I notice that your udiDirHandle is empty so something is not setup correctly there. I haven't played around much with the way you are doing it but here is a working example. This example will count the number of files and directories in a specific location defined by "sDirectory". In the below example I was not getting the directory '.' to show up but it would count '..' as the first directory. If you have more time and care you can probably look into it. There are a lot of optimizations you can do do speed the search up but this will get you running.