On 6/10/2023 3:20 PM, Eryk Sun wrote:
On 6/10/23, Thomas Passin via Python-list <python-list@python.org> wrote:
Yes; I didn't want to get too esoteric with commands that are hard to
figure out and remember, because then why not use Powershell, whose
commands are hard to figure out and remember?
Using `dir /s [/ad] [/b] "[path\]pattern"` with a wildcard pattern is
a simple way to recursively search for a filename or directory,
without needing to pipe the output to a findstr/grep/awk command. It's
also fast. Of course, CMD's wildcards aren't nearly as powerful as
regular expressions.
I used find to reduce the number of unwanted hits, which was helpful and
easy to understand even if not very powerful.
The examples I included with `for` loops in CMD were for completeness
to show how to get the results in a loop variable for further
processing in a batch script. Personally, I use `for` loops a lot even
when working at the command prompt, but I'm a dinosaur in that regard.
Using PowerShell really should be preferred nowadays.
If one is doing them every day, and especially if it's for a script that
will be reused, those loops expressions are valuable. For a one-shot
use, and for the majority of users who (I'm sure) don't use them very
often, they can be pretty obscure.
PowerShell has some kind of repulsive field effect on me. Plus it has an
ugly console appearance and seems slow. So I avoid it unless I find
some particular case I really need it for, which is hardly ever.
--
https://mail.python.org/mailman/listinfo/python-list