- Dec
- 48
- 1
I've got a small alias, "deepestFirst", that I probably should bulletproof before it goes off the rails and kills something!
It's defined as:
Its purpose is to allow executing a command (or group) in every subdirectory from the CWD on downwards, but to do it in the deepest directories first, then proceeding upwards to each parent. There are (usually rare) occasions when you'd like to do that.
I'm hoping one of our superusers, Vince, Steve, Charles, or one of our other fine members can help out here!
Some notes:
Thanks!
- forbin
It's defined as:
Code:
deep*estFirst=`for /L %ii in (32,-1,0) do (set ret=%@EXEC[ global /h /i /S+%[ii] /S%[ii] %$ ] )`
Its purpose is to allow executing a command (or group) in every subdirectory from the CWD on downwards, but to do it in the deepest directories first, then proceeding upwards to each parent. There are (usually rare) occasions when you'd like to do that.
I'm hoping one of our superusers, Vince, Steve, Charles, or one of our other fine members can help out here!
Some notes:
- This alias is an entry in my aliases.tcc file, read in during TcStart.btm.
- It obviously cheats a little and assumes it will never be run from a directory where the subdirectories are more than 32 deep. This is generally a very safe assumption for any filesystem that I've been maintaining. It doesn't seem to waste much time skipping the "too deep" values.
- I've got to say, I'm a tiny bit proud of the kludge of using /Sx /S+x to cause GLOBAL to function ONLY at depth 'x'. And a tiny bit embarrassed!
- The @EXEC[] function seems to be necessary to cause %[ii] to be expanded before GLOBAL can interpret its command switches. Otherwise the /S switches aren't interpreted correctly. Is there a better way of doing this, or should I stick with @exec?
- Would this be better defined as a small BTM file, perhaps using DO instead of FOR? My programmer's "sixth sense" tells me it might be easier to bulletproof that way.
- Would that be easier to halt via Ctrl+Break in case something goes wrong?
- Here's the biggest question: what dangers might be lurking here? It's been a while since I've written something as general-purpose as this (in JpSoft-land), and I know there are all sorts of ways that parameter expansion can go wrong. My spider senses are tingling but I can't immediately identify the danger.
Thanks!
- forbin
Last edited: