Hey guys,
CSPro 6.1 crashes when you try to use the dirlist statement, if the directory is empty.
Is there a statement that allows you to check the number of files in a directory?
Thanks,
Pierre
if direxist(tmpStr)then
ok = dirlist(fileListing,tmpStr,"*.dat",recursive);
if ok then
// 123456789012345678
// 00_00_00_00000.DAT
tmpStr = fileListing(1);
tmpStr = tmpStr[1:length(tmpStr)-18] + "...\n\n";
do a = 1 while a <= length(fileListing)
tmpStr = tmpStr + edit("99",a) + ")" + fileListing(a)[length(fileListing(a))-18+1:18] + "\n";
enddo;
S_BLOCK = tmpStr;
endif;
endif;
When the directory is empty, dirlist still returns 1 since it successfully read the empty directory. However in that case length(fileListing) is zero so when you assign tmpStr to fileListing(1) it is pointing to an invalid entry in the list and when you try to concatenate a substring from an invalid string it crashes. The right behavior is to have the call to fileListing(1) fail with an invalid subscript error and we will add that check in the next release. In the meantime you should change your logic to check both the return value of dirlist and the length of the result: