Button to subst current dir

English support forum

Moderators: Hacker, petermad, Stefan2, white

Post Reply
jjk
Member
Member
Posts: 181
Joined: 2003-07-03, 10:41 UTC

Button to subst current dir

Post by *jjk »

Hello all,
I want to subst current dir to drive s:
In a DOS window I enter
subst s: c:\foo\bar (supposed c:\foo\bar is my current dir)
This line works very well.

But how do I make a toolbar button to do that ?
I tried

Code: Select all

TOTALCMD#BAR#DATA
c:\Windows\System32\subst.exe
s: %P
but it doesn't work because %P represents current dir name followed by "\"
and "\" is the reason why subst doesn't work.
Is there any %X which represents path name without tailed \ ?

If someone has a solution, I have a second question :
how (always by the same button) to exec subst s: /d ?
(if s: is already substitued)
If no solution, I'll create another button just for this last command.

TIA
User avatar
Hacker
Moderator
Moderator
Posts: 13144
Joined: 2003-02-06, 14:56 UTC
Location: Bratislava, Slovakia

Post by *Hacker »

jjk,
subst s: .
As for the second question, I don't understand what you are trying to achieve.

Roman
Mal angenommen, du drückst Strg+F, wählst die FTP-Verbindung (mit gespeichertem Passwort), klickst aber nicht auf Verbinden, sondern fällst tot um.
User avatar
nsp
Power Member
Power Member
Posts: 1942
Joined: 2005-12-04, 08:39 UTC
Location: Lyon (FRANCE)
Contact:

Re: Button to subst current dir

Post by *nsp »

jjk wrote:Hello all,
I want to subst current dir to drive s:
In a DOS window I enter
subst s: c:\foo\bar (supposed c:\foo\bar is my current dir)
This line works very well.

But how do I make a toolbar button to do that ?
I tried

Code: Select all

TOTALCMD#BAR#DATA
c:\Windows\System32\subst.exe
s: %P
but it doesn't work because %P represents current dir name followed by ""
and "" is the reason why subst doesn't work.
Is there any %X which represents path name without tailed \ ?

If someone has a solution, I have a second question :
how (always by the same button) to exec subst s: /d ?
(if s: is already substitued)
If no solution, I'll create another button just for this last command.

TIA
What you can do is to delete before substitute new folder.

Code: Select all

command:cmd /C
parameters: subst S: /D &; subst s: "%P."
User avatar
Stefan2
Power Member
Power Member
Posts: 4281
Joined: 2007-09-13, 22:20 UTC
Location: Europa

BATCH to subst the current folder to a drive letter. Or remo

Post by *Stefan2 »

Try this batch


SubstCurrDir.cmd , v00.1/v00.2

Code: Select all

@ECHO OFF
REM BATCH to subst the current folder to a drive letter.
REM If letter is already in use, remove that subst.
REM Stefan, v00.2, 2015-11-24
REM Found at http://ghisler.ch/board/viewtopic.php?p=302535#302535


SET Folder=%~1
SET Folder=%Folder:~,-1%
SET Root=%Folder:~3,1%
IF "%Root%"=="" SET Folder=%Folder%\
SET DrvLet=%~2
SET DrvLet=%DrvLet::=%


IF exist %DrvLet%:\.. GoTo _unsubst
ECHO Do subst %Folder% as drive %DrvLet%:
REM SUBST [Laufwerk1: [Laufwerk2:]Pfad]
SUBST %DrvLet%: %Folder%
PAUSE
GoTo :EOF


:_unsubst
ECHO Do un-subst drive %DrvLet%: (%Folder%)
REM SUBST Laufwerk1: /D
SUBST %DrvLet%: /D
PAUSE
GoTo :EOF



------------------------- Total Commander Button Code Example:
TOTALCMD#BAR#DATA
%COMMANDER_PATH%\TOOLs\CMDs\SubstCurrDir.cmd
"%P" X:
C:\Windows\System32\imageres.dll,-68
SubstCurrDir


-1
-------------------------------------------------

Note: you can remove the 'Pause' commands if you wish.





I could have an use for such command since long, but was to lazy to really do it till now, so thx :D


- - -

SubstCurrDir.cmd , v00.3

More comments, more messages,...

Code: Select all

@ECHO OFF
REM BATCH to subst the current folder to a drive letter.
REM If letter is already in use, remove that subst.
REM Stefan, v00.3, 2015-11-25 
REM Found at http://ghisler.ch/board/viewtopic.php?p=302535#302535

REM Path due to TCs' "%P" parameter:
IF "%1"=="" GoTo _usage
SET Folder=%~1
REM Remove last sign, due to TCs' trailing "\":
SET Folder=%Folder:~,-1%
REM Handle root, like "C:\"
SET Root=%Folder:~3,1%
IF "%Root%"=="" SET Folder=%Folder%\

REM Wanted drive letter for subst, due to TCs' second parameter, like here 'X:':
REM POC:   IF "%2"=="" GoTo _GetNextFree
IF "%2"=="" GoTo _usage
SET DrvLet=%~2
REM Handle colons by removing provided colon and add one ourself:
SET DrvLet=%DrvLet::=%:

REM POC:   :_GetNextFree
REM POC:   rem for %%D in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do @(
REM POC:       for %%D in (z y x w v u t s r q o n m l k j i h g) do @(
REM POC:   	      IF NOT exist %%D:\.. SET DrvLet=%%D:
REM POC:   	      goto _subst
REM POC:       )
REM POC:   Working. But bad for the removing part (subst /D)
REM POC:   Would have to remember that DrvLet somewhere.


IF exist %DrvLet%\.. GoTo _unsubst

:_subst
ECHO Do subst %Folder% as drive %DrvLet%
ECHO Press any key to subst, press Crtl+C to stop!
PAUSE So you can read and stop.
REM SUBST [Laufwerk1: [Laufwerk2:]Pfad]
SUBST %DrvLet% %Folder%
PAUSE For debugging, in case something went wrong.
GoTo :EOF


:_unsubst
ECHO Do un-subst drive %DrvLet% 
SUBST
ECHO Press any key to un-subst, press Crtl+C to stop!
PAUSE So you can read and stop.
REM SUBST Laufwerk1: /D
SUBST %DrvLet% /D
PAUSE For debugging, in case something went wrong.
GoTo :EOF


:_usage
ECHO.
ECHO BATCH to subst the current folder to a drive letter.
ECHO.
ECHO Usage: 
ECHO.
ECHO ------------ Total Commander Button Code Example:
ECHO CMD   = %COMMANDER_PATH%\TOOLs\CMDs\SubstCurrDir.cmd
ECHO PARAM = "%P" X:  
ECHO ("%%P" X:, that is TCs' parameter "%%P" in quotes plus wanted drive letter, like X: )
ECHO -------------------------------------------------
ECHO.
PAUSE

Note: you can remove the 'Pause' commands if you wish.

:EOF

 
jjk
Member
Member
Posts: 181
Joined: 2003-07-03, 10:41 UTC

Post by *jjk »

Hacker, nsp, Stefan2
Many thanks to you 3. Your ideas work as I was looking to.
Once more, thanks
Post Reply