ListContains(NoCase) misses last value

Description

The newly created folder 150sq remains in the array in this snippet:

var o = expandPath(".") & \; if (! directoryExists(o & "150sq")){ directoryCreate(o & "150sq"); } var dir = directoryList(o, true); /* remove all results for the new folder */ for (var i= 1; i<= arraylen(dir); i++){ if (listContains('150sq', dir[i], '\')){ arrayDelete(dir, dir[i]); } } return dir;

Environment

Windows OS (Server 2012, 10, etc.)

Attachments

1
  • 07 Jul 2017, 12:33 pm

Activity

Show:

Pothys - MitrahSoft 11 July 2017 at 05:32

I think, i--; fixes the problem for you. This issue happens due to the modification on the currently looping array. arrayDelete() deletes the matching element in the source array. So length of the array is being reduced by one, if an element has been deleted. I just tried with a duplicate variable as follows & it gives the result for me.

<cfscript> o = expandPath(".") & "\"; if (! directoryExists(o & "150sq")){ directoryCreate(o & "150sq"); } dir = directoryList(o, true); res = duplicate(dir); /* remove all results for the new folder from the duplicated array */ for (i= 1; i<= arraylen(dir); i++){ // writeDump(dir[i] & " : " & listContains(dir[i], '150sq', '\')); if (listContains(dir[i], '150sq', '\')){ // ArrayDelete will delete only the specified object from the duplicated array. arrayDelete(res, dir[i]); } } writeDump(res); </cfscript>

And as there is no issue from server side, i'll close this ticket now. Please let us know, if you still face some issues on this.

Thanks.

Travis Peters 10 July 2017 at 12:55

Yes. I found a way to accomplish this using "contains".

for (var i= 1; i<= arraylen(dir); i++){ if (dir[i] contains '\150sq' ){ arrayDeleteAt(dir, i); i--; } }

Pothys - MitrahSoft 8 July 2017 at 03:38
Edited

, Are you trying to delete the entries of folders which are inside the target folder?

Travis Peters 7 July 2017 at 13:49

My last comment yesterday may explain why you're unable to reproduce.
I found that when I used the parameters in the correct order it worked better, although the arrayDelete did not function as expected (but that's another issue)

Pothys - MitrahSoft 7 July 2017 at 13:36

Hi

I've added test case

for this ticket & I couldn't able to reproduce the issue , I think 'ListContains' may not be any issues.

Issue seems on,

(listContains( '150sq', dir [i] , '\'))

Please verify that and let me know.

Cannot Reproduce

Details

Assignee

Reporter

Priority

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 6 July 2017 at 15:59
Updated 11 July 2017 at 05:32
Resolved 11 July 2017 at 05:32

Flag notifications