Re: How To Handle Odd Folder Names?
Posted: 10 Sep 2014 10:04
@Jeff
I don't know much about what you're trying to achieve in detail because you described "more of a concept" that you would like to do but not how exactly things should work. English isn't my mother language and it isn't always easy to understand if there aren't any real world example (and you didn't post your script or at least: relevant parts of it). You make it easier (for me) to understand what you really need by delivering something like this:
01. A general idea of what your trying to achieve and how you'd like to do that
02. A few examples of what is going wrong
03. "" of how it should have been
04. Maybe the relevant section of the code you're struggling with
After this, even if the reason is still unknown (that's the case for me up to now) I can deduct the logic from the input and the expected output.
I know the code looks (sometimes) complicated. It isn't
At least for me (or my brain). I'm not a coder, there are always more elegant ways to express logic in scripts. I (normally) document my code but in most cases not if I only post a few lines.
01. My example directories contained linebreaks instead of pipes. I'm just converting here because... 04. will use a formatlist and it's separator argument (it's missing in this case because in defaults to "|") is used for the input param AND the pattern at the end) and I didn't want to use <crlf> as the separator for the $excludeList because of this reason. If I would have posted the example directories with "|" as the separator I would omit the 01. line completely but the output would have been difficult to read.
02. It's just the list of parts of a foldername that will be excluded later on. The pipe is used because for formatlist() patterns it means "alternation" or a logical "OR" and that's what we need.
03. I'm putting a "!* at the front and a "*" at the back the pattern and replace all pipes from the $excludeList with "*|*". In the end the pattern looks like this: "!*hits*|*the*". Why? Because "hits" and "the" can be anywhere inside the path of each directory.
04. A filtering formatlist(). The filter uses "!" to inverse all the entries in it -> So it will just give back those results that don't contain any of the entries in it hence why it delivers back only two directories at the end.
I still don't know exactly what you're trying to achieve with your script (that nobody of us have ever seen) so I was just posting a general hint of how filtering can be done. Don't know if it fits the purpose. If not tell me (with examples) why it isn't the solution...

I don't know much about what you're trying to achieve in detail because you described "more of a concept" that you would like to do but not how exactly things should work. English isn't my mother language and it isn't always easy to understand if there aren't any real world example (and you didn't post your script or at least: relevant parts of it). You make it easier (for me) to understand what you really need by delivering something like this:
01. A general idea of what your trying to achieve and how you'd like to do that
02. A few examples of what is going wrong
03. "" of how it should have been
04. Maybe the relevant section of the code you're struggling with
After this, even if the reason is still unknown (that's the case for me up to now) I can deduct the logic from the input and the expected output.
I know the code looks (sometimes) complicated. It isn't
Code: Select all
01. $folders = replace($folders, "<crlf>", "|");
02. $excludeList = "hits|the";
03. $excludePattern = "!*" . replace($excludeList, "|", "*|*") . "*";
04. $result = formatlist($folders, "f", , $excludePattern);02. It's just the list of parts of a foldername that will be excluded later on. The pipe is used because for formatlist() patterns it means "alternation" or a logical "OR" and that's what we need.
03. I'm putting a "!* at the front and a "*" at the back the pattern and replace all pipes from the $excludeList with "*|*". In the end the pattern looks like this: "!*hits*|*the*". Why? Because "hits" and "the" can be anywhere inside the path of each directory.
04. A filtering formatlist(). The filter uses "!" to inverse all the entries in it -> So it will just give back those results that don't contain any of the entries in it hence why it delivers back only two directories at the end.
I still don't know exactly what you're trying to achieve with your script (that nobody of us have ever seen) so I was just posting a general hint of how filtering can be done. Don't know if it fits the purpose. If not tell me (with examples) why it isn't the solution...
Do me a favor and describe what exactly you don't understand. Quote the patterns that are hard to read / understandThe same thing goes for your optimized script in the thread where we discussed how to search for folders that *don't* contain a particular file or files