DISCLAIMER: I'm not a Groovy guy. I did not write this code. And it's not sitting in front of me, so is very pseudo.
I need to skip an item in a .eachFile list, but continue with the rest of the list.
What I have tried:
What did I try? Nothing. This is on a production system (no choice), so it really needs to be right from the first.
I'm pretty sure what I have below will work, but it's best if I get confirmation.
dir.eachFile (something)
{
Cool stuff being done here
}
What I need is
dir.eachFile (something)
{
preliminary cool stuff
if (Test condition)
{
finish doing cool stuff
}
}
Or is something like this a better idea? I'm leaning toward the first way. Seems simpler, unless there's a reason for doing it differently.
dir.eachFile (something)
{
preliminary cool stuff
if (not Test condition)
{
skip this file and break/continue/return to top of loop
}
finish doing cool stuff
}
So, how would I skip the rest of the loop code and return to the top? I've seen multiple ways, but none of them specifically say they work with an eachFile method. Return? Continue? Break?. I think Break will just kill the whole thing, not skip, which would be a non-starter.
Ideally, the "bad" files would be moved to BadFile directory, not just skipped, using code in an "else" after the "if". Is Java/Groovy strict about things like that? I'm probably over-thinking...this is operating off a list, yes? Not touching the actual file unless it passes the test condition.