ZTree.com  | ZEN  | About...  

 Index   Back

Two F9 Menu Scripts That Actually Work   [Wish]

By: John Gruener     Orlando, Florida  
Date: Jul 13,2009 at 06:32
In Response to: [Wish] Rename Mask with Disk Volume? (Michael Kahn)

> For tagged files:
>
> SET ZTTagged=False
> REM #ZTIfTagged SET ZTTagged=True
> IF [%%ZTTagged%%]==[False] GOTO Err_NoTag
> ::
> :: The following requires tagged files
> ::
> REM #ZTTag #ZTTemp\~ZTTag.bat -fCALL #ZTTemp\ZTW_MENU.BAT SUB1 %1
> IF "%%1"=="SUB1" GOTO Sub1
> CALL #ZTTemp\~ZTTag.bat
> DEL /Q #ZTTemp\~ZTTag.bat
> PAUSE Press any key to return to Ztree...
> GOTO End
> :Sub1
>   COPY /V %1 %j2:\%j3\servername-%4.%5
>   SHIFT
> GOTO End
> :Err_NoTag
>   ECHO This menu item requires tagged files to operate
>   PAUSE Press any key to return to Ztree...
> :End

Michael,

You can't possibly have tested this!

Errors:
1. Since ZTree's %j3 includes a leading slash, you must not specify it. Use %j2:%j3 instead.

2. Since SUB1 is reentrant, you must use double percents (%%1) to access the tagged files. A single %1 will not get it.

3. In SUB1 if the command is to use %%1 for the tagged files, the SHIFT command must come before the execution command, not after it. I prefer to simply use %%2 for the tagged files and eliminate the SHIFT altogether. (See Example 2 in Help file).

4. In SUB1 you cannot use %4.%5 because at this point these refer to the current file name, not the tagged file names.

5. PAUSE in Windows XP does not display the message on the PAUSE line. I usually use ECHO followed by PAUSE >NUL

Fixes and Enhancements:
1. In order to get just the target file names, and not the entire paths, we must parse the source name to get just the file name. For the %%2 parameter use %%~nx2.

2. Since the script depends on a split screen, I added a check to see that the screen is indeed split.

3. The VOL command can be parsed with FOR TOKENS to get the volume name, so instead of a script for each volume, only one script will be necessary. I added this along with checks that the VOL command did indeed return the expected message, and the volume name was not blank.

4. I added a confirmation message before starting the copy.

5. It's not really necessary to delete the ~ZTTag.bat file since ZTree will automatically overwrite it on another execution, and delete it when it exits.

6. Since there will be just one command for each tagged file, it is not necessary to add the complication of the reentered SUB1 subroutine at all. Just specify the command on the ZTTag line so that ~ZTTag.bat itself is generated with the COPY commands. (See Example 1 in Help file). In that case you must use %4.%5, since ZTree is substituting the file names on that line. Below are F9 scripts for both methods.

F9 Menu Using SUB1
::  Check if this is being reentered:
IF [%%1]==[SUB1] GOTO Sub1
::  Check that there is at least one tagged file:
SET _Tagged=False
REM #ZTIfTagged SET _Tagged=True
IF [%%_Tagged%%]==[False] GOTO Err_Usage
::  Check that ZTree is in split-screen mode:
IF "%j1"=="" GOTO Err_Usage
::  Obtain the source volume name:
FOR /F "TOKENS=1-6" %%%A IN ('VOL %~d1') DO (
  IF /I [%%%A]==[volume] IF /I [%%%B]==[in] IF /I [%%%C]==[drive] IF /I [%%%E]==[is] (
    SET _VolName=%%%F
    GOTO Confirm
  )
)
GOTO Err_Volume
::  Display a message to confirm the copy:
:Confirm
ECHO.
ECHO.   This will copy all tagged files in the current file window to directory:
ECHO.      %j2:%j3
ECHO.
ECHO.   These files will be renamed by prepending the source volume name as follows:
ECHO.      %_VolName%_(filename.ext)
ECHO.
CHOICE.COM /N "   Continue? (Y/N)..."
IF ERRORLEVEL 2 GOTO End
::  Generate ~ZTTag.bat with a line for each tagged file that reenters this menu script:
REM #ZTTag #ZTTemp\~ZTTag.bat -fCALL #ZTTemp\ZTW_MENU.BAT SUB1 %1
::  Call the generated ~ZTTag.bat file:
CALL #ZTTemp\~ZTTag.bat
::  Display message when finished:
GOTO Pause
::  Reentered subroutine that is called for each tagged file:
:Sub1
COPY /V %%2 %j2:%j3\%_VolName%_%%~nx2
GOTO End
::  Error messages:
:Err_Usage
ECHO.
ECHO.   This copies tagged files to the opposite side of a split.
ECHO.
ECHO.   There must be tagged files in the current File Window,
ECHO.
ECHO.   and ZTree must be in the Split Screen mode.
GOTO Pause
:Err_Volume
ECHO.
ECHO.   Error: Cannot obtain a volume name for drive %~d1
GOTO Pause
:Pause
ECHO.
ECHO.   Press any key to return to ZTree...
PAUSE >NUL
GOTO End
:End

F9 Menu Without Using SUB1
::  Check that there is at least one tagged file:
SET _Tagged=False
REM #ZTIfTagged SET _Tagged=True
IF [%%_Tagged%%]==[False] GOTO Err_Usage
::  Check that ZTree is in split-screen mode:
IF "%j1"=="" GOTO Err_Usage
::  Obtain the source volume name:
FOR /F "TOKENS=1-6" %%%A IN ('VOL %~d1') DO (
  IF /I [%%%A]==[volume] IF /I [%%%B]==[in] IF /I [%%%C]==[drive] IF /I [%%%E]==[is] (
    SET _VolName=%%%F
    GOTO Confirm
  )
)
GOTO Err_Volume
::  Display a message to confirm the copy:
:Confirm
ECHO.
ECHO.   This will copy all tagged files in the current file window to directory:
ECHO.      %j2:%j3
ECHO.
ECHO.   These files will be renamed by prepending the source volume name as follows:
ECHO.      %_VolName%_(filename.ext)
ECHO.
CHOICE.COM /N "   Continue? (Y/N)..."
IF ERRORLEVEL 2 GOTO End
::  Generate ~ZTTag.bat with a line for each tagged file:
REM #ZTTag #ZTTemp\~ZTTag.bat -fCOPY /V %1 %j2:%j3\%_VolName%_%4.%5
::  Call the generated ~ZTTag.bat file:
CALL #ZTTemp\~ZTTag.bat
::  Display message when finished:
GOTO Pause
::  Error messages:
:Err_Usage
ECHO.
ECHO.   This copies tagged files to the opposite side of a split.
ECHO.
ECHO.   There must be tagged files in the current File Window,
ECHO.
ECHO.   and ZTree must be in the Split Screen mode.
GOTO Pause
:Err_Volume
ECHO.
ECHO.   Error: Cannot obtain a volume name for drive %~d1
GOTO Pause
:Pause
ECHO.
ECHO.   Press any key to return to ZTree...
PAUSE >NUL
GOTO End
:End

- John

900 views      
Thread locked
 

Messages in this Thread

 
96,656 Postings in 12,233 Threads, 350 registered users, 30 users online (0 registered, 30 guests)
Index | Admin contact |   Forum Time: May 13, 2024 - 7:56 am UTC  |  Hits:63,424,825  (5,975 Today )
RSS Feed