CD to "next dir" ??

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Sep 11, 2012
59
1
#1
I wonder how I could make an alias that let me go to the "next directory" at the same level.

If the alias is called CDNEXT

Example
¨
c:\
c:\Dir1
c:\Dir1\SubDirA
c:\Dir1\SubDirB
c:\Dir2
c:\Dir2\SubDirC

Command => Result
In c:\Dir1 - CDNEXT ==>> c:\Dir2
In c:\Dir1\SubDirA ==>> c:\Dir1\SubDirB

In the follow folders, the command would be "invalid"
c:\Dir1\SubDirB
c:\Dir2
c:\Dir2\SubDirC

Why ?
For example, cleanup in a bunch of folders.

Why not use GUI/File Manager ??
Due to Visual impairment

Thanks for any tip!
 

samintz

Scott Mintz
May 20, 2008
1,232
11
Solon, OH, USA
#2
Try this. Copy it into CDNEXT.BTM
Code:
setlocal
dir /f /a:d /o:n .. > ..\$.tmp
do i = 0 to %@lines[..\$.tmp]
  iff '%@line[..\$.tmp,%i]' == '%_cwd' then
    set dn=%@line[..\$.tmp,%@inc[i]]
    iff '%dn' == '**EOF**' then
      beep
    else
      cd %dn
    endiff
    leave
  endiff
enddo
del /q ..\$.tmp
endlocal /d
 
Jul 6, 2008
255
4
#3
I wonder how I could make an alias that let me go to the "next directory" at the same level.

If the alias is called CDNEXT

Example
¨
c:\
c:\Dir1
c:\Dir1\SubDirA
c:\Dir1\SubDirB
c:\Dir2
c:\Dir2\SubDirC

Command => Result
In c:\Dir1 - CDNEXT ==>> c:\Dir2
In c:\Dir1\SubDirA ==>> c:\Dir1\SubDirB

In the follow folders, the command would be "invalid"
c:\Dir1\SubDirB
c:\Dir2
c:\Dir2\SubDirC

Why ?
For example, cleanup in a bunch of folders.

Why not use GUI/File Manager ??
Due to Visual impairment

Thanks for any tip!
Scott provided the solution to your OP.
Just thought I would add one more to the mix.
These btm's can be used together to visit all directories in a tree.
Code:
─────────────────────────────────────────────────────────────
XOVER.BTM             12/09/2014 16:29           3,131 bytes
  When used with XIN, changes to the next subdirectory at the same level as the current directory after executing XIN. Moves up
 one directory and then down to the next one in order.

XIN.BTM               12/09/2014 16:35           2,270 bytes
  Changes to the first subdir of your current directory. Moves down one directory level from the current; used in tandem with x
over.btm is a method to traverse through an entire directory structure, one directory at a time.
────────────────────────────────────────────────────────────────
These were written by Klaus Meinhard many years ago. I may have tweaked them a bit. Enjoy!
 

Attachments

samintz

Scott Mintz
May 20, 2008
1,232
11
Solon, OH, USA
#4
Another option would be to pre-populate a dirstack and just keep POPD-ing to go down the list.
Code:
do d in /a:d * (pushd %d)
You can use DIRS to see the list.
 
#6
Code:
alias CDNEXT=`(if "..\%@filename[%CD]" ne "%@FINDFIRST[..\*,+D-L]" do until  "..\%@filename[%CD]" eq "%@FINDNEXT[..\*,+D-L]" (REM) ) & *CD %@FINDNEXT[..\*,+D-L] & if %@FINDCLOSE[] ne 0 BEEP`
 
Jul 6, 2008
255
4
#8
Another option would be to pre-populate a dirstack and just keep POPD-ing to go down the list.
Code:
do d in /a:d * (pushd %d)
You can use DIRS to see the list.
Thanks.
I get a "Change directory" popup menu when I use this method.
x'ing out of all the menu's produces a dirs stack with several duplicate directories in the stack.
Not sure exactly what I have in my particular settings, so I need to do further testing.
One thing I did add was a /x to keep these directories from being placed in the dir history.
 
Jul 6, 2008
255
4
#9
I wrote these a couple of years ago. I map my <C-N> to next, and <C-P> to prev
I assume the mappings (<C-N> to next, and <C-P> to prev) you're using are keyboard aliases:
alias @@ctrl-n=`next.btm`
alias @@ctrl-p=`Prev.btm`

The <ctrl-p> doesn't work on my setup. Need to do some further investigation.

Probably will just use a different key combination.

Thanks for contributing!
 
#10
Thanks.
I get a "Change directory" popup menu when I use this method.
x'ing out of all the menu's produces a dirs stack with several duplicate directories in the stack.
Not sure exactly what I have in my particular settings, so I need to do further testing.
One thing I did add was a /x to keep these directories from being placed in the dir history.
Why not just change it to:

Code:
do d in /a:d * (pushd %@full[%d])
 
Jul 6, 2008
255
4
#11
Why not just change it to:

Code:
do d in /a:d * (pushd %@full[%d])
Tried your suggestion and this is the result:
Code:
D:\bat>do d in /a:d * (pushd %@full[%d])
TCC: (Sys) The system cannot find the path specified.
 "\BAT\4dosbof\4dostips"
TCC: (Sys) The system cannot find the path specified.
 "\BAT\4dosbof\4dtnt"
TCC: (Sys) The system cannot find the path specified.
 "\BAT\4dosbof\4xbtm6"
TCC: (Sys) The system cannot find the path specified.
 "\BAT\4dosbof\4xbtm7"
...................
After all the errors, one for each directory in c:\bat, I was left here with only d:\bat in the stack.
Code:
D:\BAT\4dosbof>dirs
D:\bat
Does this actually work on your system?
 
#14
alias ..*.....=%0\
I don't believe that gives the desired behavior. I think this does (using a couple of plugins).
Code:
v:\> d /a:d /b /f
V:\4pluginsPre17
V:\20000files
V:\cksum
V:\ip
V:\IPReg
V:\zippers

v:\> cdin

v:\20000files> cdnext

v:\4pluginspre17> cdnext

v:\cksum> cdnext

v:\ip> cdnext

v:\ipreg> cdnext

v:\zippers>