Replicating CMD's cd with wildcards?

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
#1
In CMD.exe, I can do something like cd *doc*, and it will change into the first matching directory. TCC LE didn't like this. Is this an appropriate replacement? It seems to work.
cd %@FINDFIRST[%1*]
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,415
40
Albuquerque, NM
prospero.unm.edu
#2
In CMD.exe, I can do something like cd *doc*, and it will change into the first matching directory. TCC LE didn't like this. Is this an appropriate replacement? It seems to work.
cd %@FINDFIRST[%1*]
At the command line, it's easier to use filename completion. You don't even need the CD command; just type DOC, hit Tab until the directory name you want appears, then Enter.

In a batch file.... I can't imagine why you'd ever want an indeterminate CD in a batch file. But if you're going to use @FINDFIRST, be sure to call @FINDCLOSE afterwards to free up the search handle. It might be easier to call @EXPAND and strip off the first word.
 
#3
In a batch file.... I can't imagine why you'd ever want an indeterminate CD in a batch file. But if you're going to use @FINDFIRST, be sure to call @FINDCLOSE afterwards to free up the search handle. It might be easier to call @EXPAND and strip off the first word.
Why? Because laziness rules my life. I want to run builds in one or more subdirectories, but not move from the current dir in the end. Furthermore, I just want to say doBuild dom *client serv where dom is short for domain, serv is short for server, and *client actually means web-client.

I've got it all working in CMD, and mostly working in TCCLE. I didn't know about findclose, thanks. Looks like %@WORD[1,%@EXPAND[%1*, d]] works just as well.

Except:
I also want to sometimes build the current dir, . or the parent, .. Neither findfirst nor expand resolve .* or ..*, so it looks like I must add special logic for this. Any thoughts here?

Pat.
 
#5
Should that be .\* and ..\* ?
No, expanding either of those will be an arbitrary directory, and not the current directory or the parent directory.

What this seems to boil down to is that . and .. are not in the list of directories listed by EXPAND or FINDFIRST...

Here's what dir /ad shows:

Code:
 2/02/2010  10:50         DIR    .
 2/02/2010  10:50         DIR    ..
 2/02/2010  10:20         DIR    .svn
 2/02/2010  10:21         DIR    apache-ssl
 2/02/2010  10:38         DIR    logs
And here is what %@EXPAND[*, d] shows:
.svn apache-ssl logs
Note the missing entries... Is there a way to add these special directories back in? I'd have less crazy if logic, if I could.</dir></dir></dir></dir></dir>
 
#6
Does something like %@expand[%@full[.]] work for you? Using %@full[] with a
pattern simulates what it would look like and keeps the pattern. Using it
with dot gives the cwd.

On Tue, Feb 2, 2010 at 10:41 AM, pforhan <> wrote:


> ---Quote (Originally by Charles Dye)---
> Should that be .\* and ..\* ?
> ---End Quote---
> No, expanding either of those will be an arbitrary directory, and not the
> current directory or the parent directory.
>
> What this seems to boil down to is that . and .. are not in the list of
> directories listed by EXPAND or FINDFIRST...
>
> Here's what dir /ad shows: 2/02/2010 10:50 <DIR> .
> 2/02/2010 10:50 <DIR> ..
> 2/02/2010 10:20 <DIR> .svn
> 2/02/2010 10:21 <DIR> apache-ssl
> 2/02/2010 10:38 <DIR> logs
>
> And here is what %@EXPAND[*, d] shows:
> .svn apache-ssl logs
>
> Note the missing entries... Is there a way to add these special directories
> back in? I'd have less crazy if logic, if I could.
>
>
>
>
>


--
Jim Cook
2010 Sundays: 4/4, 6/6, 8/8, 10/10, 12/12 and 5/9, 9/5, 7/11, 11/7.
Next year they're Monday.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
3,415
40
Albuquerque, NM
prospero.unm.edu
#7
What this seems to boil down to is that . and .. are not in the list of directories listed by EXPAND or FINDFIRST...

Here's what dir /ad shows:

Code:
 2/02/2010  10:50         DIR    .
 2/02/2010  10:50         DIR    ..
 2/02/2010  10:20         DIR    .svn
 2/02/2010  10:21         DIR    apache-ssl
 2/02/2010  10:38         DIR    logs
And here is what %@EXPAND[*, d] shows:

.svn apache-ssl logs
Note the missing entries... Is there a way to add these special directories back in? I'd have less crazy if logic, if I could.
Something like this, perhaps.... ?

Code:
set dirs="%_cwd" "%@truename[..]" %@expand[*,d]
And then use DO /L %DIRS to loop through the list?
 
#8
Does something like %@expand[%@full[.]] work for you? Using %@full[] with a
pattern simulates what it would look like and keeps the pattern. Using it
with dot gives the cwd.
I see this behavior, too, however it does not work for .* or ..*

I've written the if logic for the . and .. cases, so that these will not go through the cd wildcard craziness. It should still work under CMD, too.
 
#10
In CMD.exe, I can do something like cd *doc*, and it will change into the first matching directory. TCC LE didn't like this. Is this an appropriate replacement? It seems to work.
cd %@FINDFIRST[%1*]
By the way, I know TCC is not trying to be exactly like CMD... where is the line drawn between a defect/bug and intentional changes?
 

samintz

Scott Mintz
May 20, 2008
1,228
11
Solon, OH, USA
#11
Forgive me for jumping into this mid-conversation as I may be stating
something obvious, but doesn't this do what you want?

for /a:d %d in (*) do echo %d

-Scott

Charles Dye <> wrote on 02/02/2010 02:02:33 PM:


> ---Quote (Originally by pforhan)---
> What this seems to boil down to is that . and .. are not in the list
> of directories listed by EXPAND or FINDFIRST...
>
> Here's what dir /ad shows:
>
>
> Code:
> ---------
> 2/02/2010 10:50 DIR .
> 2/02/2010 10:50 DIR ..
> 2/02/2010 10:20 DIR .svn
> 2/02/2010 10:21 DIR apache-ssl
> 2/02/2010 10:38 DIR logs
> ---------
> And here is what %@EXPAND[*, d] shows:
> .svn apache-ssl logs
>
> Note the missing entries... Is there a way to add these special
> directories back in? I'd have less crazy if logic, if I could.
> ---End Quote---
> Something like this, perhaps.... ?
>
>
> Code:
> ---------
> set dirs="%_cwd" "%@truename[..]" %@expand[*,d]
> ---------
> And then use DO /L %DIRS to loop through the list?
>
>
>
>
 
#13
pforhan wrote:
| ---Quote (Originally by samintz)---
| Forgive me for jumping into this mid-conversation as I may be stating
| something obvious, but doesn't this do what you want?
|
| for /a:d %d in (*) do echo %d
| ---End Quote---
| That's interesting, in that it lists . and .. -- where @EXPAND and
| @FINDFIRST do not. Is that a defect?

No, it WAD. FOR has an option to suppress the dot directories: /H, provided
many years ago at the request of lots of users. Your usage is the first I
came across that actually desires the . and .. directories in my many years
of using command processors.
--
HTH, Steve
 
#14
No, it WAD. FOR has an option to suppress the dot directories: /H, provided
many years ago at the request of lots of users. Your usage is the first I
came across that actually desires the . and .. directories in my many years
of using command processors.
That's what I assumed. I know my usage is a bit odd, but so is Maven, for anyone who's used it.

Maven allows you define a large hierarchy of projects, but frequently you just want to recompile a subset of those. Here's a typical use case:

Code:
cd longNamedDomain
mvn clean install
cd ../longNamedServer
mvn clean install
cd ../longNamedClient
mvn clean install
cd ../longNamedDistribution
mvn deploy
cd..
... annoying. But I found myself doing that because I didn't want to build the other 20 parts of the project, in order to save time. So, I wrote a script that lets me do the above, all in one line, failing fast if there was a problem:

Code:
selbuild *dom *serv *cli deploy *dist
There are rare cases where I'm already in one of those subdirs, so I want to reference '.' -- for example, assuming I'm in client:

Code:
selbuild ..\*dom ..\*serv . deploy ..\*dist
I think this is a huge win. I'd be happy to share the script if anyone would like to take a look.
 
#15
pforhan wrote:
| That's what I assumed. I know my usage is a bit odd, but so is
| Maven, for anyone who's used it.
|
| Maven allows you define a large hierarchy of projects, but
| frequently you just want to recompile a subset of those. Here's a
| typical use case:
|
|
| Code:
| ---------
| cd longNamedDomain
| mvn clean install
| cd ../longNamedServer
| mvn clean install
| cd ../longNamedClient
| mvn clean install
| cd ../longNamedDistribution
| mvn deploy
| cd..
| ---------
| ... annoying.

If you use the CDPATH variable (see help topic cdpath.htm), include .. as
one of the directories to search for the target, and the current directory
does not also include a subdirectory with the same name as the target, the
command
cd longNamedDistribution
will actually act as if it were "cd ../longNamedDistribution".

| But I found myself doing that because I didn't want
| to build the other 20 parts of the project, in order to save time.
| So, I wrote a script that lets me do the above, all in one line,
| failing fast if there was a problem:
|
|
| Code:
| ---------
| selbuild *dom *serv *cli deploy *dist
| ---------
| There are rare cases where I'm already in one of those subdirs, so I
| want to reference '.' -- for example, assuming I'm in client:
|
|
| Code:
| ---------
| selbuild ..\*dom ..\*serv . deploy ..\*dist
| ---------
| I think this is a huge win. I'd be happy to share the script if
| anyone would like to take a look.

I think the use of CDPATH would make this simpler. You could also
incorporate into your script an automatic search for target directory names
one level up from the CWD, and a special symbol for the current directory
(other than . which is not always processed as you might intend) if %_cwd is
too much to type. Note that in a command like
selbuild ..\*dom ..\*serv %_cwd deploy ..\*dist
the variables, including %_cwd, are evaluated by the TCC parser BEFORE the
"selbuild" command is executed, so you need not worry about unexpected
directory changes. OTOH, .. is not evaluated, so if your script changes
directories (witout backtracking) a second reference to .. may mean a
different directory. However, I am sure you already take care of such
sideeffects.
--
HTH, Steve
 

samintz

Scott Mintz
May 20, 2008
1,228
11
Solon, OH, USA
#16
I assume that the issue is the expanding of the wildcard directory names
you've specified as the arguments to selbuild.

I also assume you invoke Maven for each argument. So, selbuild 1 2 3,
would invoke Maven 3 times. Whereas selbuild foo, only invokes it once.

selbuild.btm:
if %1.==. goto usage

do until %1.==.
for /a:d %d in (%1) do (pushd "%d" & mvn clean install & popd)
shift
enddo
quit

:usage
echo selbuild dir1 [dir2 [dir3] ...]


-Scott

pforhan <> wrote on 02/03/2010 10:01:30 AM:


> ---Quote (Originally by Steve Fábián)---
> No, it WAD. FOR has an option to suppress the dot directories: /H,
provided

> many years ago at the request of lots of users. Your usage is the first
I

> came across that actually desires the . and .. directories in my many
years

> of using command processors.
> ---End Quote---
> That's what I assumed. I know my usage is a bit odd, but so is
> Maven, for anyone who's used it.
>
> Maven allows you define a large hierarchy of projects, but
> frequently you just want to recompile a subset of those. Here's a
> typical use case:
>
>
> Code:
> ---------
> cd longNamedDomain
> mvn clean install
> cd ../longNamedServer
> mvn clean install
> cd ../longNamedClient
> mvn clean install
> cd ../longNamedDistribution
> mvn deploy
> cd..
> ---------
> ... annoying. But I found myself doing that because I didn't want
> to build the other 20 parts of the project, in order to save time.
> So, I wrote a script that lets me do the above, all in one line,
> failing fast if there was a problem:
>
>
> Code:
> ---------
> selbuild *dom *serv *cli deploy *dist
> ---------
> There are rare cases where I'm already in one of those subdirs, so I
> want to reference '.' -- for example, assuming I'm in client:
>
>
> Code:
> ---------
> selbuild ..\*dom ..\*serv . deploy ..\*dist
> ---------
> I think this is a huge win. I'd be happy to share the script if
> anyone would like to take a look.
>
>
>
>
 
#17
I assume that the issue is the expanding of the wildcard directory names
you've specified as the arguments to selbuild.
Basically, yeah. I can add the if logic to avoid this issue, it's just that, in my batch file, I went from this:
Code:
cd %1*
to this:
Code:
rem change to requested dir. Use special rules when running under TCC:
if (%@EVAL[1+1]%)==(2) goto cdUnderTCC
cd %1*
goto runMvn

:cdUnderTCC
if (%1)==(.) goto runMvn
if (%1)==(..) cd .. & goto runMvn
cd %@WORD[0,%@EXPAND[%1*,d]]
goto runMvn

:runMvn
Granted, if I drop support for CMD, I can drop half those lines. This is just a bit more complex, that's all, but it still works.
 

samintz

Scott Mintz
May 20, 2008
1,228
11
Solon, OH, USA
#18
This works for me both under CMD and TCC. I have not tested under TCC/LE.

if %1.==. goto usage

:l1
if %1.==. goto :EOF
for /d %%d in (%1) do (pushd "%%d" & mvn clean install & popd)
shift
goto l1

:usage
echo selbuild dir1 [dir2 [dir3] ...]


I tested it with
selbuild . .. ..\*CE*

"." mvn clean install
".." mvn clean install
"..\WINCE420" mvn clean install
"..\WINCE500" mvn clean install
"..\WINCE600" mvn clean install
"..\Windows CE Tools" mvn clean install

It is assumed that the dirX's specified as the arguments are relative
paths, or wild cards. Note that, "..\*CE" will only find directories that
end with "CE", whereas "..\*CE*" finds all the directores with "CE" in
their name.


-Scott



pforhan <> wrote on 02/03/2010 01:42:19 PM:


> ---Quote (Originally by samintz)---
> I assume that the issue is the expanding of the wildcard directory names

> you've specified as the arguments to selbuild.
> ---End Quote---
> Basically, yeah. I can add the if logic to avoid this issue, it's
> just that, in my batch file, I went from this:
>
> Code:
> ---------
> cd %1*
> ---------
> to this:
>
> Code:
> ---------
> rem change to requested dir. Use special rules when running under TCC:
> if (%@EVAL[1+1]%)==(2) goto cdUnderTCC
> cd %1*
> goto runMvn
>
> :cdUnderTCC
> if (%1)==(.) goto runMvn
> if (%1)==(..) cd .. & goto runMvn
> cd %@WORD[0,%@EXPAND[%1*,d]]
> goto runMvn
>
> :runMvn
> ---------
> Granted, if I drop support for CMD, I can drop half those lines.
> This is just a bit more complex, that's all, but it still works.
>
>
>
>