Welcome!

By registering with us, you'll be able to discuss, share and exchange private messages with other members of our community.

SignUp Now!

How to? alias to go to the directory that contains a file?

May
308
6
I would like to know how to write an alias that goes to a directory, given a filename that is inside it, with the complete path.
For example, something such as
Code:
reach "C:\Program Files\JPSoft\TCMD29\tcstart.btm"
I tried several variants, but none of them works.
For example,
Code:
reach=cdd "%@path[%*]"
If I type
Code:
reach C:\Program Files\JPSoft\TCMD29\tcstart.btm
I get
Code:
TCC: (Sys) The system cannot find the file specified.
 " C:\Program Files\JPSoft\TCMD29\tcstart.btm"
Searching for "expand" in the help it says that I can use CTRL-F, instead it is CTRL-W.
Anyway, if I type
Code:
reach C:\Program Files\JPSoft\TCMD29\tcstart.btm
and then I press CTRL-W I get
Code:
cdd "%@path[%*]" C:\Program Files\JPSoft\TCMD29\tcstart.btm
How can I write such an alias?
Thank You and regards
Rodolfo Giovanninetti
 
I do something similar, but not as an alias;
Code:
@setlocal
@echo off
iff %# eq 0 then
  input Enter a file mask: %%filemask
else
  *set filemask=%1
endiff

OPTION //ConsolePopupWindows=Yes

iff %@len[%filemask] gt 0 then
  everything /f /s /w %filemask > clip:
  *set kount=%@lines[clip:]
  iff %kount eq -1 then
    echo No files matching %filemask were found.
  else
    iff %kount eq 0 then
      set thefile=%@clip[0]
      defer cdd %@path["%thefile"] > nul
    else
      Gosub DateAndFilename
      iff defined SELECT_LINE then
       set words=%@words["%results"]
       iff %words eq 3 then
         echo %@word[1,"%results"] %@word[2,"%results"]
         set results=%@word[1,"%results"] %@word[2,"%results"]
       else
         set results=%@word[0,%results]
       endiff
       echo %results > clip:
       defer cdd "%@path[%results]"
       defer type clip:
       defer dir %filemask
      endiff
    endiff
else
  echo USAGE: %_batchname file.ext
endiff

OPTION //ConsolePopupWindows=No

endlocal
quit

:DateAndFilename
if exist %temp\c2p.txt del /q %temp\c2p.txt
do kount=0 to %@lines[clip:]
  set theline=%@clip[%kount]
  echo %@filedate["%theline"] %theline >>%temp\c2p.txt
enddo

*set results=%@select[%temp\c2p.txt,1,1,20,80,Select a file from the list,-1]
*set rightmost=%@eval[%@len[%results]-11]
*set results=%@right[%rightmost,%results]
*set results="%results"
Return

Thus, if I want to find the file tcstart.btm;
Code:
c2p.btm tcstart.btm
...I am presented with all locations of tcstart.btm, I select the one that I want, and I am taken to the location of the file.

This is not a solution to your post, but sharing this that it may help in your solution.

Joe
 
I would like to know how to write an alias that goes to a directory, given a filename that is inside it, with the complete path.
For example, something such as
Code:
reach "C:\Program Files\JPSoft\TCMD29\tcstart.btm"
I tried several variants, but none of them works.
For example,
Code:
reach=cdd "%@path[%*]"
If I type
Code:
reach C:\Program Files\JPSoft\TCMD29\tcstart.btm
I get
Code:
TCC: (Sys) The system cannot find the file specified.
 " C:\Program Files\JPSoft\TCMD29\tcstart.btm"

You just need one tiny change:

Code:
C:\>alias reach=`cdd "%@path[%$]"`

C:\>reach C:\Bin\TCmd29\tcstart.btm

C:\Bin\TCmd29>

Use %$ for an alias's parameters, %* for a batch file's parameters.
 
I typically take advantage of Everything Search. For example, I have a folder named: C:\Program Files\LunaSA\CSP\test.
I can type cdd csp\test and I get a pop-up window with all the folders on my PC that contain that. I select it and done.
 
@Rodolfo, I'm curious. Under what circumstances would this be useful?

I played around with a keystroke plugin that handled <Shift-Enter>. Basically, it checks whether the path part of the current command line is a directory and if it is, CDD there. So, for example, d:\tc29\tcc.exe<Shift-Enter> would CDD to d:\tc29. It works, though it could probably be made more robust.

So I wondered if the same could be done with an autoexecute keystroke (@@key) alias. The answer seems to be no because, as far as I can tell, autoexecute keystroke aliases don't get arguments. So I thought of the following; maybe it will become a suggestion.

Let autoexecute keystroke aliases get, as arguments, the current command_line_in_progress. That could make such aliases more useful (they could refer to %$, %1, ...). If the user didn't want the alias to get arguments, he could prefix the alias with the EraseLine keystroke (Esc) as the help suggests.

Have I overlooked anything? Is that not a good idea? Comments appreciated.
 
Here's another way to do the same thing:

Code:
C:\>alias reach=`%$\..\`

C:\>reach C:\Bin\TCmd29\tcstart.btm

C:\Bin\TCmd29>reach "c:\Program Files\Notepad++\notepad++.exe"

C:\Program Files\Notepad++>

%$ gives us the alias arguments, and adding \..\ to the end makes it an automatic directory change to the parent directory.
 
Yes.

(That's been the default since 4DOS, and I don't know why anyone would turn it off. But I suppose someone must have requested the option.)

Looks like AutoCDD was added 8/2009 (v11). Rex commented that it was by request. And Steve Fabian asked

Why the heck would anybody want to disable this useful feature anyway?
 

Similar threads

Back
Top