by intrepidhero · 3y ago · 0 comments
I fall back on `for filename in os.listdir():`
https://www.shellcheck.net/wiki/SC2012
"ls is only intended for human consumption: it has a loose, non-standard format and may "clean up" filenames to make output easier to read."
dash$ touch "hi ho"
dash$ touch "there, buddy"
dash$ for f in *; do echo $f; done
hi ho
there, buddy
(EDIT: That was in a scratch directory.) But as @npongratz alludes to in sibling https://news.ycombinator.com/item?id=34727735 find . [predicates] -print0 | xargs -0
is bulletproof and directory scanning, output, and input loops all run at full C speed. (One predicate is `-maxdepth 1` to not recurse.) touch -- -nAnyway, I did mention find-xargs, but it's also true your leading dash filenames mistaken for options point can cause trouble in naive invocations if find roots begin with dashes. Doubtless, a lotta gotchas..