ZTree Keyboard Macros (F12)

[UP] Macros Application Menu Configuring

Contents
  1. What are ZTree keyboard macros?
  2. Do I really need to use macros?
  3. ZTree macro operation
  4. Manually coding and executing a macro
  5. Manually coding but not executing macros
  6. Recording keystrokes in a macro
  7. Macro history and bookmarking
  8. Macro history navigation
  9. Organizing bookmarks
  10. Documenting bookmarks
  11. Macro files (.ZTM)
  12. Using F9 menu items in macros
  13. Running macros from the ZTree command line
  14. Possible enhancements
  15. ZTree macro language reference
  16. Macro examples
  17. More examples

What are ZTree Keyboard Macros?

ZTree Keyboard Macros ("macros" in the rest of this document) provide yet another powerful mechanism for speeding up, re-using, and sharing your work. Macros allow you to store a sequence of keystrokes as a "program" that you, or anybody else you share it with, can later execute. Like all other user input in ZTree, macros have their own history list for easy retrieval, editing or bookmarking.

All macro operations are built around the F12 key, making learning and using this feature surprisingly easy.
Contents

Do I really need to use macros?

Even very experienced ZTree users shy away from using macros, probably because ZTree's economy and efficiency of keystrokes lets them perform long and complex tasks relatively easily. Unfortunately, this may become a habit, reducing file management to the drudge typically imposed by GUI-based tools.

Windows is notorious for discouraging, even making it impossible, to automate anything. This elusively simple point-and-click environment forces the user to do all the work, all the time, many times, with the environment keeping no history of previous steps. With the exception of desktop shortcuts and macros in MS Office (used by only the most advanced users), there is no mention of automation or batch processing in this GUI environment.

Yet, decades ago, computer use always implied programming and automating tasks, with all the advantages that this brings. This was so natural in the command line world, and most users typically achieved a level of efficiency they were happy with by reducing the amount of typing they had to do and automating frequent tasks.

Not so today. Hundreds of millions of people spend endless hours interacting with a machine without realizing how much of their lives they waste by interacting via long-winded dialog boxes, constantly added and "enhanced" icons, themes, skins, and other eye-candy...

Using macros in ZTree requires some learning and discipline, both of which are psychological obstacles and a major challenge to our habits, thanks to the UI "evolution" from command line to point-and-shoot. The command line forced one to come up with command aliases, scripts and macros -- all wonderful inventions for reliably speeding up well-defined tasks.

The GUI wasn't designed to be automated, so the amount of user manual work is constant at best, but, of course, we know that it is ever-increasing. With no features built into the GUI to reduce the work (by automating, encapsulating), the number of clicks in a maze of options just keeps growing, taking a toll on your time, memory, nerves... It's very simple: if there is no way to memorize your clicks and other actions on the machine, the human is condemned to repeat them later over and over -- provided the organic human memory is still willing to co-operate...

Macros in general, and those in ZTree in particular, offload your memory and reduce complex tasks to just a few keystrokes, which are the only thing you need to remember.

If you don't find any of the examples shown here of any use, force yourself to observe how you use ZTree and spot one of those tasks that you do often (say, more than 3 times per session) and which consists of more than 5-6 keystrokes. It does not matter how trivial the task is. Then, store the keystrokes in a macro and start using it exclusively to perfom the task. When F12 followed by Alt+(bookmark) leading to the task becomes a habit, you are on your way, and you won't regret it!
Contents

ZTree macro operation

Interactive ZTree macro functions are implemented using the F12 key and its variants.
Contents

Manually coding and executing a macro

  1. Press F12 in DIR or FILE view to call the ZTree macro editor/launcher. The MACRO: prompt appears.
  2. Enter a comma-separated list of macro tokens at the prompt, for example: ESC,SPLIT,TAB,DOWN,LEFT,CTRL_T, etc.
  3. Press Enter to finish macro coding. Your work will be saved in the macro history.
  4. ZTree will proceed to execute it (once) immediately.
  5. (If you would like to run it several times, recall it from history and supply the repeat count via F4.)

Manually coding but not executing macros

On those occasions when you don't feel comfortable with the above approach, it is possible to just create and save the macro without executing it. To do this, instead of pressing Enter, press Alt+UpArrow to finish the macro coding phase. This will save the macro definition in the history, but not execute it.

You will remain in the macro editor/launcher mode. You can keep adding new macros to the macro history, commenting them, or adding bookmarks in this way as long as you like. Leave the editor/launcher mode by pressing ESC.
Contents

Recording keystrokes in a macro

You actually don't have to learn macro tokens at all, just ask ZTree to watch what you are doing and code the macro for you. However, in this mode, ZTree will save the tokens in a disk file, not in the macro history.
  1. Press Ctrl+F12 (ZTree opens the ZSAVE.ZTM file and enters the "learn" mode)
    An "R" starts flashing in the right corner
  2. Perform the dir/file actions as usual
    ZTree translates your keystrokes into macro tokens and writes them in ZSAVE.ZTM
  3. Press Ctrl+F12 to finish macro coding. You are done. (ZTree closes ZSAVE.ZTM)
    The flashing "R" disappears
  4. Press F12, and at the MACRO: prompt, enter @ZSAVE.ZTM to execute the macro
Contents

Macro history and bookmarking

To use macros residing in the macro history, one just needs to perform these steps:
  1. Press F12 (in DIR or FILE views) to enter the macro editor/launcher.
    The MACRO: prompt appears.
  2. Press UpArrow or DownArrow keys to invoke the macro history list
  3. Navigate to a macro
  4. Press Enter to execute it

As your macro usage grows, you will want to "bookmark" macros by selecting them in the macro history and pressing Insert -- such macros will be marked with a special character and stay in the history list forever. If you don't bookmark your macros, they may eventually scroll off the history list, so take special care of frequently used and/or complex macros.

A much more useful and efficient way of bookmarking and executing macros is to use alphanumeric markers, rather than the above generic marker. 26 letters and 10 digits allow for a total of 36 unique bookmarks.

To make use of this feature, choose a letter or digit that you want to associate with the macro, 'A' for example. To create the bookmark, proceed as above, but instead of bookmarking by pressing Insert, press Ctrl+A. An 'A', rather than the generic marker, will appear next to the macro in the macro history.

The next time you want to execute this particular macro, just press F12 followed by Alt+A. This will recall and execute the macro for you -- you don't have to go searching for it in the history. In other words, macro execution (of your favorite 36 macros) can be reduced to just these 2 steps:

  1. Press F12 (in DIR or FILE view) to enter the macro editor/launcher
  2. Press Alt+A to execute it

You may also choose to recall the macro from history, but not execute it immediately -- sometimes a wise thing to do:

  1. Press F12 (in DIR or FILE views) to enter the macro editor/launcher. The MACRO: prompt appears.
  2. Press Ctrl+A to bring the macro from the history to the MACRO: prompt
  3. Edit it, press Enter to execute it, or press ESC to abandon execution

In other words: F12,Alt+% = F12,Ctrl+%,Enter, where % stands for any letter (A-Z) or digit (0-9).
Contents

Macro history navigation

When the macro history is invoked (F12, followed by Up/Down), the desired macro can be selected as usual -- using Up/Down, PgUp/PgDn, Home/End. Pressing Enter brings the selected history entry to the MACRO: prompt.

However, there is faster method: if your macro is bookmarked with, say, letter M, instead of navigating, just press M, and the macro will be brought to the MACRO: prompt.

You may also press Alt+M to immediately execute it -- this shortcut works regardless of whether the history is visible or not!
Contents

Organizing bookmarks

Organizing a potential maximum of 36 favorite macros, in addition to many others residing in the macro history, as well as .ZTM files, takes time and thought. Choosing bookmarks and file names that are easy to remember and associate is essential, otherwise, we are back to slow, manual navigation and selection mode. There is also the risk of totally abandoning macros and "regressing".

Fortunately, a chosen alphanumeric (or generic) bookmark character can easily be modified. When the macro history is called (F12, Up, for example), pressing Insert will simply remove any bookmark character (if there is one) next to the selected macro entry. If a bookmark character is not present, Insert will add a generic bookmark -- Insert is a toggle.

Similarly, pressing Ctrl+(bookmark) also works as a toggle -- it will add/remove an alphanumeric bookmark.

Using the above techniques, bookmark characters can be renamed and moved around until they make the most mnemonical sense to the user.

Note that ZTree will make sure that bookmarks are unique, so don't be surprised if sometimes nothing happens after pressing Ctrl+(bookmark). This simply means that the bookmark character is already taken and needs to be freed first.

Again, getting this right gives the user a collection of 36 2-keystroke commands (F12,Alt+(bookmark)) that greatly extend ZTree's power and boost productivity -- provided they become second nature.
Contents

Macro files (.ZTM)

To simplify managing (and sharing) a large number of macros, it is practical to store them in external .ZTM files, rather than in private macro histories. Of course, they can be stored in both.

The easiest way of generating .ZTM files is to use the Ctrl+F12 function. It will record the macro in the {ZTWdir}ZSAVE.ZTM file automatically. Note that this file will actually be overwritten every time, so it may need to be renamed, if you want to keep the macro for future use.

Since .ZTM files are pure text files, they can be easily edited and comments added using ';' as the first character in a line. In addtion, comments can be safely added to the macro file by making use of the STOP directive.

Sample commented macro file (NETJUNK.ZTM)
;
; This is a sample macro file
;
\,ALT_I,*,b,f,ENTER,ALT_S,ASCEND,d,END,STOP,
Logs the "Temporary Internet Files" branch and sorts files by Date.
This directory must first be stored in the Treespec history and
bookmarked with I.
Contents

Using F9 menu items in macros

Just like playing back the usual ZTree keystrokes, or executing shell commands via the eXecute command, nothing prevents macros from executing Application Menu scripts. In fact, these scripts simply just prepare a .BAT file for execution by the shell.

But thanks to this extra level and the huge space provided by menus, many new possibilities emerge.

In addition, certain tokens (like #ZTversion) are only visible in F9 scripts. There are currently no similar environment variables, so going via F9 is often the only solution available to a programmer.

See examples:

  • Process tagged files with F9 batch scripts
  • Upgrade running ZTW.EXE from ztwNNNNN.zip
    Contents

    Documenting macros

    Unfortunately, once the number of macros grows, even good organization may not help you remember what a macro really does and what that bookmark X stands for. In other words, you should consider documenting somewhere what those long lists of comma-separated tokens in your macro history stand for. (Note that giving meaningful names to your .ZTM files and including comments solves the problem for macros stored in files.)

    The most logical place to document macros is in the history list itself, by creating non-executing macro entries. There are at least two ways of doing this by using "comment" tokens.

    If a macro starts with an 'x', it will start its execution with the shell eXecute command. The command interpreter (CMD.EXE, for example) knows how to ignore comments, so, putting 'x::' or 'xREM' at the beginning of a macro will not do anything! If this macro is executed by accident, it will do no damage, other than leave the user in the command line mode (and requiring ESC to be pressed).

    Since ZTree also recognizes the STOP directive, it seems more appropriate to use that for neutralizing macros. This approach will not even have the overhead of launching the shell -- everything will be much cleaner and faster.

    Below is a sample macro history list, with certain commented macros shown. Clearly, since history entries move around, the mix of executable and commented entries looks a bit chaotic.

    Sample macro history
    . ALT_X,NET USE %2
    . x:: F Eject CD-ROM in drive F:
      ESC,LEFT,ENTER,ESC,LEFT,ENTER,ESC,LEFT,ENTER,UP,LEFT,LEFT
    . x:: L Locate the longest file names in current branch
    . x:: O Open (START) current file in a separate window
    . x:: P Popup the Windows Properties box for current file or dir
    . x:: I Log the "Temporary Internet Files" branch and sort files by Date
    . x:: C Copy current file to Clipboard
      STOP,CTRL_INS,w,t
    . ALT_X,C:\3\nteject E:,ENTER
    J ALT_R,D,e,ALT_X,C:\3\nteject E:,ENTER
    . STOP,In histories we must use Ctrl/Shift+Insert instead of ^C/^V
    . STOP,TODO: http://www.ztw3.com/forum/forum_entry.php?id=37248
    . STOP,TODO: 37518
    O ALT_X,start /min "Popup" "C:\3\context.exe" %1,ENTER
    L ESC,ESC,*,b,ALT_S,l,END,ALT_I
    I \,CTRL_I,ENTER,*,b,f,CTRL_I,ENTER,ALT_S,ASCEND,d,END
    1 F9,1,*,ENTER
    . x:: S Search text files for some string
    . x:: E Mirror current branch tree (without any files)
    . x:: J Eject CD-ROM in drive E:
    P ALT_X,C:\1\propsfor.exe %1,ENTER,ESC
    V ALT_X,DIR %2,ENTER
    ...
    

    To make a ZTree history list more readable, you may do the following from time to time: quit ZTree and edit the ZTW.HST text file by grouping the comments on top of the list. If you don't attempt to execute any of the commented items, they will stay near the top forever, even as items on the bottom are added, deleted, or modified.

    Sample macro history (edited)
    . x:: C Copy current file to Clipboard
    . x:: E Mirror current branch tree (without any files)
    . x:: F Eject CD-ROM in drive F:
    . x:: I Log the "Temporary Internet Files" branch and sort files by Date
    . x:: J Eject CD-ROM in drive E:
    . x:: L Locate the longest file names in current branch
    . x:: O Open (START) current file in a separate window
    . x:: P Popup the Windows Properties box for current file or dir
    . x:: S Search text files for some string
    . STOP,In histories we must use Ctrl/Shift+Insert instead of ^C/^V
    . STOP,TODO: http://www.ztw3.com/forum/forum_entry.php?id=37248
    . STOP,TODO: http://www.ztw3.com/forum/forum_entry.php?id=37518
    . x:: -- The lines above are comments, executable macros start below --
    . ALT_X,NET USE %2
    . ALT_X,C:\3\nteject E:,ENTER
    J ALT_R,D,e,ALT_X,C:\3\nteject E:,ENTER
    O ALT_X,start /min "Popup" "C:\1\context.exe" %1,ENTER
      ESC,LEFT,ENTER,ESC,LEFT,ENTER,ESC,LEFT,ENTER,UP,LEFT,LEFT
    L ESC,ESC,*,b,ALT_S,l,END,ALT_I
    I \,CTRL_I,ENTER,*,b,f,CTRL_I,ENTER,ALT_S,ASCEND,d,END
    1 F9,1,*,ENTER
      STOP,CTRL_INS,w,t
    P ALT_X,C:\1\propsfor.exe %1,ENTER,ESC
    V ALT_X,DIR %2,ENTER
    ...
    

    Here is yet another way of using the STOP directive, this time to put the comments at the end of the macro. You will be saving many history entries for real use, but potentially ending with some very long lines in the history.

    Comments as part of the macro
    ...
    J ALT_R,D,e,ALT_X,C:\3\nteject E:,ENTER,STOP,-- Eject CD-ROM in drive E:
    O ALT_X,start /min "Popup" "C:\1\context.exe" %1,ENTER,STOP,-- Open (START)
       current file in a separate window
    L ESC,ESC,*,b,ALT_S,l,END,ALT_I,STOP,-- Locate the longest file names in current branch I \,CTRL_I,ENTER,*,b,f,CTRL_I,ENTER,ALT_S,ASCEND,d,END,STOP,-- Log the
       "Temporary Internet Files" branch and sort files by Date
    P ALT_X,C:\1\propsfor.exe %1,ENTER,ESC,STOP,-- Popup the Windows Properties
       box for current file or dir
    ...
    Contents

    Running macros from the ZTree command line

    One of the most powerful features of ZTree is using it, when appropriate, as a batch enhancer tool, that is, executing a command like: ZTW /K@MYMACRO.ZTM or ZTW /Kkey,key,key,key,...

    Building or acquiring tested and documented macros extends ZTree's power immensely. In fact, the futile debates over mouse/keyboard, GUI/console applications, and other user interface matters become irrelevant in a mindset oriented towards a solutions-based approach to file management. ZTW becomes just another command line (scripting) utility, with its very special language.

    Of course, building "solutions" requires learning the "language" (that is, the ZTree UI and knowing how to capture the keys with Ctrl+F12). However, using "solutions" requires absolutely no learning, just obtaining them from a reliable source and understanding what they do.

    As it is, the macro language is quite powerful, but a few more enhancements would make it more robust and reliable.
    Contents

    Possible enhancements

    See Macro ZEPs
    Contents

    ZTree macro language reference

    The ZTree macro language consists of two sets of tokens (keyboard key codes and directives) that are understood and interpreted by the macro processor. See the official list in ZTW.HLP, section 3.10, as the table below may not be up to date.

    Keyboard key codes
    The keyboard key codes must be entered in UPPER case.
    Special keys:
    F1..F12, BKSP, BTAB, COMMA, DEL, DOWN, END, ENTER, ESC, HOME,
    INS, LEFT, NUM5, PGDN, PGUP, RET, RIGHT, SEMI, SPACE, TAB, UP, QUOTE
    
    Shift keys, where x is:
    ALT_x   - 0..9, A..Z, F1..F12, DOWN, HOME, LEFT, RIGHT, UP
    CTRL_x  - 0..9, A..Z, F1..F12, BKSL, BKSP, BTAB, DOWN, END, ENTER, HOME, 
              INS, LEFT, PGDN, PGUP, RET, RIGHT, SH_LEFT, SH_RIGHT, TAB, UP, [, ]
    SH_x    - F1..F12, BKSP, DEL, DOWN, END, ESC, HOME, INS, LEFT, NUM-, 
              NUM1..NUM9, NUM_INS, PGDN, PGUP, RIGHT, TAB, UP
    
    Macro directives
    Macro directives are special tokens that can be inserted in the macro stream, along with keyboard key codes. Their function is to control the macro "program" flow, set specific options to a known state, or serve as debugging aids.

    STOP - Unconditionally stops macro execution and discards the rest of the sequence. This may be useful for stepping through long, complex, macros by simply inserting one or more STOP codes before critical parts in the macro. Once a section of the macro is debugged, the STOP is edited out, allowing more of the macro to be visible. STOP is also very handy for commenting out entire macros (or documenting them) -- it is sufficient to put a STOP as the very first token in a macro to turn it into an inoffensive comment.

    STOP_IF_MATCH - Abort macro immediately if there are files in the FW
    STOP_IF_NOMATCH - Abort macro immediately if there no files in the FW
    STOP_IF_TAGS - Abort macro immediately if some files are tagged
    STOP_IF_NOTAGS - Abort macro immediately if no files are tagged
    STOP_IF_SPLIT - Abort macro immediately if ZTree is in Split mode
    STOP_IF_UNSPLIT - Abort macro immediately if ZTree is not in Split mode
    STOP_ON_ERROR - Abort macro when any error condition is raised
    STOP_ON_HOME - Abort macro if the current position is already at home
    STOP_ON_END - Abort macro if the current position is already at end
    SPLIT, UNSPLIT - Splits/Unsplits the screen vertically
    ASCEND, DESCEND - Sets the sort order in Alt-Sort
    BEEP - Generate an audible beep
    SLEEP - Suspend the current macro for 1 second
    PAUSE - Prompt to continue or abort the current macro
    Looping directives
    WHILE_NOT_ERROR - Repeat rest of macro until any error condition is raised
    WHILE_NOT_END - Repeat rest of macro until the current position is already at end
    WHILE_NOT_HOME - Repeat rest of macro until the current position is already at home
    Contents

    Macro Examples

    The best way to learn ZTree macro programming is to study a few examples, contibuted by the ZTree user community worldwide.

    The macro history list is where (shorter and simpler) macros typically live. In the examples below, an attempt was made to choose bookmark alphanumeric markers that can easily be associated with familiar file operations -- F12,Alt+C to Copy the Current file to the Clipboard.

    The safest place to store, debug and test a macro is in a file. Here too, we have tried to come up with descriptive names for the .ZTM files. Feel free to apply your own naming convention, but, please, come up with one.

    When macro tokens are highlighted like this, code outside ZTree is being executed (an external .EXE, .BAT, a shell command line, an explicit or implicit START command, etc.) via the x (eXecute) command.

    When tokens are colored like this, an entry in the ZTree Application Menu is being executed via the F9 command. These entries are also external .EXE, .BAT, or shell commands, executed temporarily outside ZTree.

    A token colored like this is a bookmarked history entry to be fetched by the macro.

    The following terms will be used in the examples. Please refer to the ZTree online help (F1) for details:

    Contents

    F12,Alt+0 Rename ZSAVE.ZTM to ZSAVE_yyyymmddhhnn.ZTM (@RENAME_ZSAVE.ZTM)
    Description Renames the current #ZThome\ZSAVE.ZTM file, thus preserving its contents from subsequent macro recording (Ctrl+F12) commands, that would otherwise overwrite it. To record macros, one may now want to develop the habit of hitting F12,Alt+0 just before hitting the initial Ctrl+F12.
    Scope: DIR and FILE views. Split mode may be on or off.
    Origins: 1
    NOTE: This macro would be unnecessary if ZTree had a configuration option that would do some sort of renaming automatically whenever the initial Ctrl+F12 is hit. However, the macro is generic enough to be still useful for renaming (Viewing, Moving, Copying, Editing, Deleting, adding to an archinve, etc.) any other file needing special and frequent attention.
    Bookmark  0 - Zero the macro recording environment for fresh use
    Code
    \,CTRL_BKSP,%#ZThome%,ENTER,ENTER,f,ZSAVE.ZTM,ENTER,STOP_IF_NOMATCH,
    r,*:_yyyymmddhhnn:.*,STOP
    \
    CTRL_BKSP
    Navigate (using the Treespec command) to where the ZSAVE.ZTM file resides, which is always the ZTree installation directory, pointed to by the #ZThome environment variable.
    %#ZThome%
    ENTER,ENTER
    Users install ZTree in a variety of places, so using %#ZThome% makes the macro totally portable.
    f,ZSAVE.ZTM,ENTER
    STOP_IF_NOMATCH
    Look for #ZThome\ZSAVE.ZTM. If there isn't one, terminate the macro.
    r
    *:_yyyymmddhhnn:.*
    Rename the file, using one of the many masks that ZTree provides. This one will insert a date/time string into the file name part and leave the extension as is.
    STOP The macro will actually stop at this point allowing the user to put the last touches on the rename mask before hitting the final ENTER (or aborting with ESC).
    F12,Alt+1 Release all drives except one (@LOG_H.ZTM)
    Description Releases all drives from memory, except one (drive H in this case).
    Scope: DIR and FILE views. Split mode may be on or off.
    Origins: Hartmut Schneider
    Bookmark  1 - Leave only 1 drive logged
    Code
    CTRL_L,H,ALT_R,d,ABCDEFGIJKLMNOPQRSTUVWXYz,f,ENTER,F8,F8
    CTRL_L,H Relog (or switch to) drive H
    ALT_R,d Invoke Release drive function
    ABCDEFGIJ
    KLMNOPQR
    STUVWXYz
    Specify all disks (A-Z), except H. Note that all drive letters are in uppercase except z, which terminates the drive selection dialog. UPPERCASED letters allow multiple-drive entries without terminating the dialog; the first lowercased letter will terminate it.
    f,ENTER Set Filespec to *.*
    F8,F8 Toggle Split state twice, resulting in the same Split configuration as that preceding the macro. However, if we started with two panes, both of them will now show drive H. This is necessary, since all other drives are no longer valid and should not appear in any pane after macro execution.
    It is very easy to create similar macros to log any number of specific local and/or network drives matching exactly the tasks at hand and store them in files like LOG_CDEF.ZTM, LOG_MP3_BURN.ZTM, LOG_PROJ3.ZTM, etc.
    F12,Alt+C Copy current (text) file to Clipboard (@COPY2CLIP.ZTM)
    Description Copies the current file to the Windows Clipboard for later global use by any application. Most applications support copying and pasting to/from the Clipboard as a very practical and efficient means of exchanging data.
    Scope: FILE view with a current (highlighted) file. DIR view will also work, provided there is at least one file in the directory. Split mode may be on or off.
    NOTE: Copying files other than text files may give unpredictable results.
    Bookmark  C - Strongly associated with copying and the standard Windows Ctrl+C keystroke.
    Code
    ESC,ESC,ENTER,v,g,HOME,ENTER,END,ENTER,F4,ESC,STOP, Good for text files only!
    ESC,ESC
    ENTER
    Make sure we are in FILE view. Hopefully, there will be a selected file to work on...
    v Invoke View
    g Activate the Gather function
    HOME Jump to top of file
    ENTER Start selecting lines
    END Jump to end of file, i.e., the last line
    ENTER Stop selecting lines
    F4 Copy selected lines (the entire file in this case) to the Clipboard
    ESC Leave View
    STOP Most useful while debugging, the STOP directive also allows adding comments at the end of the macro.
    F12,Alt+A Append current (text) file to Clipboard with advance (@APPEND2CLIP.ZTM)
    Description Appends the current file to the Windows Clipboard and moves the cursor to the next file.
    Scope: FILE view with a current (highlighted) file. DIR view will also work, provided there is at least one file in the directory. Split mode may be on or off.
    NOTE: Appending files other than text files may give unpredictable results.
    Bookmark  A - Append
    Code
    ESC,ESC,ENTER,v,g,HOME,ENTER,END,ENTER,F5,ESC,DOWN,STOP, Good for text files only!
    ESC,ESC
    ENTER
    Make sure we are in FILE view. Hopefully, there will be a selected file to work on...
    v Invoke View
    g Activate the Gather function
    HOME Jump to top of file
    ENTER Start selecting lines
    END Jump to end of file, i.e., the last line
    ENTER Stop selecting lines
    F5 Append selected lines (the entire file in this case) to the Clipboard
    ESC,DOWN
    STOP
    Leave View and position the cursor on the next file, hopefully, the next candidate for append. If a large number of adjacent files is destined for Clipboard appending, hitting Alt+F12 repeatedly will be all the work required.
    F12,Alt+E Open current directory in Explorer (@EXPLORE.ZTM)
    Description Use this macro when you really must open Explorer and work in the directory you are currently looking at in ZTree. You will bypass that painful Explorer navigation.
    Origins: 1
    Scope: FILE, DIR and Autoview views. Split mode may be on or off.
    Note: Because Explorer uses commas as a delimiter, the COMMA token needs to be used to handle this bizarre convention. Also, experiment by removing the /select,"%2:%3" switch from the macro -- Explorer will behave differently.
    Bookmark  E - Strongly associated with Explorer and the standard Windows Win+E shortcut.
    Code
    x,CTRL_BKSP,
    @start explorer.exe /n,COMMA,/e,COMMA,/root,COMMA,"%2:%3",/select,COMMA,"%2:%3",
    CTRL_ENTER
    x,CTRL_BKSP Launch the shell and clear the input field completely
    @start
    explorer.exe
    /n
    Execute the shell command. In this case, we are launching a new instance of the Windows Explorer and making use of its command line options. (Prefixing user input in ZTree with '@' is, in the majority of situations, optional -- it tells ZTree to not keep it in its history.)
    /e,/root,
    "%2:%3"
    Tell Explorer to set the current drive\directory (%2:%3) as the "root" of its display. This can be used to hide My Computer, other disks, and other objects, and thus speed up Explorer considerably. You will be resricted to a "virtual disk" that will be much easier to manage.
    /select,
    "%2:%3"
    Tell Explorer to focus on the current drive\directory (%2:%3). Note that the presence of /select will override the behaviour of /root, i.e., the upper level dirs on the current disk, and all other disks will be visible in the new Explorer instance.
    CTRL_ENTER Execute the shell command, and return immediately to where you were in ZTree
    F12,Alt+F Find string in file(s) (@SEA_BETA.ZTM)
    Description Searches a frequently used set of files for a frequently used string, in Autoview mode. In the example below, C:\ZTree\BETA*.TXT files will be searched for bugfixes that involved the Alt+F5 keystroke.
    Scope: FILE and DIR views. Split mode may be on or off.
    Bookmark  F - Find
    Code
    ESC,ESC,\,ALT_Z,f,BETA*.TXT,ENTER,ENTER,CTRL_T,CTRL_S,Fixed*Alt*F5,
    ENTER,CTRL_F4,F7
    ESC,ESC Make sure ZTree is in DIR view
    \ Invoke Treespec navigation in order to jump to a particular directory that we had already bookmarked with a single letter or a digit.
    ALT_Z Fetch bookmark Z, C:\ZTree in this example. This keystroke moves us to this directory and highlights it.
    f Invoke Filespec in order to select only those files that we are interested in
    BETA*.TXT Select only BETA*.TXT files in C:\ZTree
    ENTER Filespec does its work...
    ENTER Enter C:\ZTree. Some selected files will be shown, hopefully
    CTRL_T Tag all displayed files (BETA*.TXT, in this case)
    CTRL_S Invoke Search Tagged Files
    Fix*Alt*F5 Specify the search string. Note the use of the '*' wildcard
    ENTER Search does its work
    CTRL_F4 Display only those files that are still tagged and hide all others. (Search leaves tags only on those BETA*.TXT files that contain the requested string. All other BETA*.TXT files will have been untagged by Search.)
    F7 Invoke Autoview. Note that, if the requested string is not found in *any* of the files, all the files will be untagged and CTRL_F4 will, therefore, not do anything -- you will enter Autoview with all BETA*.TXT files selected. However, this is very easy to see, since the diamond characters next to file names will be missing.
    F12,Alt+L Locate files with the longest file names (@LONGEST.ZTM)
    Description ZTree has a unique feature for sorting files by their name length. This is often needed when programs (like those used for staging CD-ROMs for burning) complain about certain file names being too long. This macro will pinpoint them easily. Try this on your Profiles\Favorites folder, for example.
    Scope: FILE, DIR and Autoview views. Split mode may be on or off.
    Bookmark  L - Longest file names locator
    Code
    ESC,ESC,*,b,ALT_S,l,END,x, ALT_7,ESC,ALT_I
    ESC,ESC Make sure ZTree is in DIR view
    * Expand current branch/disk
    b Flatten the file list
    ALT_S,l Invoke the Sort menu and sort by file Length
    END Jump to end of file list
    x, ALT_7,
    ESC
    The sorting is done, and we want to alert the user by eXecuting bookmark 7 in the eXecute command history. Bookmark 7 happens to be a command line -- C:\1\ZTW\SUCCESS.BAT %1 %2 %3 %4 %5 %6 -- which will be executed in a DOS box. Once the DOS box is closed, control returns to ZTree's macro processor. In this example, SUCCESS.BAT has been customized to execute the simple command ECHO {BELL}.

    SUCCESS.BAT template
    @echo OFF
    goto BEEP
    :: goto SOUND
    :: goto OPEN
    :: goto EXPLORE
    :: goto ZTREE
    :: goto MAIL
    ::
    :: SUCCESS.BAT -- Alerts the user in various ways that an
    ::                operation has been completed successfully.
    ::                There are many choices...
    ::
    :: 1. Just beep on the console. The single byte after the ECHO command
    ::    has a value of binary 7 (^G) -- you must use an editor capable of
    ::    entering this non-printable value.
    :BEEP
    @ECHO 
    goto EXIT
    ::
    :: 2. Play a tune. Note that you may not hear any BEEPs or sounds
    ::    if you have earphones plugged in and they disable the speaker(s)!
    :SOUND
    c:\1\PLAYWAV DONE.WAV
    goto EXIT
    ::
    :: 3. Launch other type of application or multimedia content
    ::    using standard Windows associations. You just need to specify
    ::    a file name or a directory and let START do the work:
    :OPEN
    :: START C:\BACKUP_REPORT.HTML
    :: START file.JPG, file.AVI, file.XLS, ...
    goto EXIT
    ::
    :: 4. Launch Explorer in the directory ZTW ended up after doing its work.
    ::    Use drive and directory tokens passed by ZTree's eXecute command:
    :EXPLORE
    START %2:%3
    goto EXIT
    ::
    :: 5. Launch another copy of ZTree in the directory ZTW ended up after
    ::    doing its work. Use drive and directory tokens passed by ZTree's
    ::    eXecute command:
    :ZTREE
    START C:\1\ZTW\ZTW.EXE %2:%3
    goto EXIT
    ::
    :: 5. Send a mail message to your mobile phone or other mail account:
    :MAIL
    SET SUBJECT="Backup done, shutting down PC"
    C:\1\BLAT REPORT.LOG -t SMTP%%08112233678@MYSMS.NET -s %SUBJECT%
    goto EXIT
    :: goto SHUTDOWN
    ::
    :SHUTDOWN
    C:\1\REBOOT -shutdown
    :EXIT
    :: @Pause
    

    ALT_I Display additional file information, which will reveal the entire file name, regardless of the current screen width. window. It is now very easy to just use the Up arrow to view the actual file names, starting with the longest name at the bottom.
    F12,Alt+Y Mirror an empty tree structure (Interactive) (@MIRROR_I.ZTM)
    Description Mirrors (duplicates) the current branch without copying any files. This macro does all the work and then places you in the Destination Directory Picker (F2), where you decide where you want the tree created. You also have to decide how much of the source path you want replicated.
    Scope: FILE, DIR and Autoview views. Split mode may be on or off.
    Bookmark  Y - emptY tree
    Code #1
    ESC,ESC,ALT_L,t,ALT_M,F2 (You must navigate to your destination)
    ESC,ESC Make sure ZTree is in DIR view
    ALT_L,t Log current branch's tree only (we don't need the files)
    ALT_M Invoke the tree Mirror menu
    F2 Invoke the Destination Directory picker and select a destination
    F12,Alt+M Mirror an empty tree structure (Automatic) (@MIRROR_A.ZTM)
    Description Mirrors (duplicates) the current branch without copying any files. This macro is totally automatic (unlike Alt+Y): by setting up the target directory in the other pane of a Split view, you will not need to answer any questions.
    Scope: FILE and DIR. Split mode must be on.
    Bookmark  M - Mirror
    Code #2
    ESC,ESC,ALT_L,t,ALT_M,ENTER,C,ENTER (You must be in Split mode)
    ESC,ESC Make sure ZTree is in DIR view
    ALT_L,t Log current branch's tree only (we don't need the files)
    ALT_M Invoke the tree Mirror menu
    ENTER Accept Destination Directory shown in the other pane
    c Specify that the copying starts with the Current source dir
    ENTER Go!
    F12,Alt+R Rename dir/file to Word Caps format, then advance (@WORDCAPS.ZTM)
    Description Renames files or dirs to the Word Caps format. For example, "john LENNON.txt" becomes "John Lennon.Txt" and "\TREE" becomes "\Tree". Once the macro is executed, it becomes the current macro, so it can be followed by Alt+F12 (which auto-repeats) to rename a large number of files to the above (or any other) desired format.
    Scope: FILE, DIR and Autoview views. Split mode may be on or off.
    Bookmark  R - Rename
    Code
    r,TAB,ENTER,DOWN
    r Invoke the Rename menu
    TAB Select the first format from the Change Case cycle. To select another format, use up to 3 TAB tokens here. In addition, by adding CTRL_TAB tokens to the macro, the file extension part format can be controlled separately from the file name part.
    ENTER Execute the rename on the current object
    DOWN Move selector down to next file/dir
    F12,Alt+2 Synchronize two directory branches (@SYNC2DIRS.ZTM)
    Description Preparation: the screen is split (F8) into the left (source dir) and right (target dir) panes. The dirs must be chosen carefully. The results will be - interesting - if the branches overlap! The two directories and their subdirectories (branches), if any, will then be synchronized, resulting in two identical areas, without any extra or missing files in either of them. This is similar to a clean ZTree Mirror operation, but without unnecessarily moving identical files.
    Scope: FILE and DIR views. Split mode must be on.
    Origins: 1 2
    Bookmark  2 - Synchronize 2 directories
    Code
    ESC,ESC,*,ALT_C,ENTER,ENTER,CTRL_B,ALT_C,ENTER,ENTER,r,ENTER,y,ESC,ESC,
    TAB,ESC,ESC,*,ALT_C,ENTER,n,ENTER,CTRL_B
    ESC,ESC Make sure ZTree is in DIR view
    * Log entire branch
    ALT_C Compare Branch operation started
    ENTER Accept the directory in the other pane as the target for comparison
    ENTER Look for Unique (yes) and Newer (yes) files only. (Alternatively, you may choose to look for Identical (yes) and then Ctrl+Invert the tags after the CTRL_B step below.)
    CTRL_B All tagged files (if any) in the branch are selected and
    ALT_C,ENTER copied as *.* (default)
    ENTER to the other pane,
    r,ENTER with relative paths.
    y Overwritting files automatically must be chosen here, since it is not possible to interact with the user reliably from within a macro.
    ESC,ESC The copying is over; make sure the source pane remains in DIR view.
    TAB Move focus over to the other pane. Here, we'll perform the reverse of the above, more or less.
    ESC,ESC Make sure ZTree is in DIR view here as well.
    * Log entire branch
    ALT_C Compare Branch operation started
    ENTER Accept the directory in the other pane as the target for comparison
    n,ENTER Look for Unique (yes) files only -- these are the extra files that no longer exist in the master area, and we want to single them out!
    CTRL_B All tagged files (if any) in the branch are selected and the macro stops here. The user decides what to do with them: delete them with Ctrl+D, move them with Ctrl+M, archive them with Ctrl+F5, or leave them alone.
    F12,Alt+9 Process tagged files using F9 batch scripts (@TAG_F9.ZTM)
    Description Creates the C:\TEMP\LONGLST.$$$ file from the currently tagged files and jumps to the first script in F9 that starts with the string "9". The macro then stops, allowing the user to select an item and press Enter to execute it. This allows operations that go beyond those provided by ZTree's powerful Ctrl+Batch, Alt+Batch and other built-in tag-related features. In fact, any function that ZTree cannot (currently) do with tagged files directly, can probably be implemented via this mechanism.
    Scope: FILE view only with at least one tagged file. Split mode may be on or off.
    Bookmark  9 - Batch process tagged files via F9
    Code
    CTRL_B,ALT_L,Y, ALT_L, F9,9,*
    CTRL_B Invoke BATCH processing dialog
    ALT_L Fetch a bookmarked history entry, rather than having to type in a file name. In this example, the entry bookmarked as L is C:\TEMP\LONGLST.$$$. The name was chosen because full (long) paths will be used.
    Y This is a critical detail: if the file C:\TEMP\LONGLST.$$$ already exists, ZTree will ask you if you want to overwrite the file. You have to say Y, otherwise the operation is cancelled. I make sure the file already exists (by simply never deleting it), but this needs finer control.
    ALT_L Fetch a bookmarked history entry, rather than having to type in a file mask. In my case, the entry bookmarked as L is "%1", which will store full (long) paths and put them between double quotes. After this point, ZTree generates the list file, which may look like:

    "C:\1\ZTW\ZTW_MENU.DA$"
    "C:\1\ZTW\XTG_MENU.DAT"
    "C:\1\ZTW\ZTW.ZAM"
    "C:\1\ZTW\ZTW_MENU_200205301425.DAT"
    "C:\1\ZTW\ZTW_MENU_200205301444.DAT"
    "C:\1\ZTW\ZTW_MENU_200205052156.DAT"
    

    F9 Call the application menu. At this point C:\TEMP\LONGLST.$$$ exists, so you can execute any scripts that rely on it.
    Note: If there are no currently tagged files, and the scripts don't know how to handle this situation, the results are unpredictable.
    9 Use spell search to jump to the first entry that starts with a 9. You may call it "9 Tagged files batch job template" and put the following generic code in it:

     9 Tagged files batch job template
    01 @echo OFF
    02 IF NOT EXIST C:\TEMP\LONGLST.$$$ GOTO ERROR
    03 SET JOB=DIR/B
    04 echo Command: '%job%' will be applied to:
    05 echo.
    06 TYPE C:\TEMP\longlst.$$$
    07 echo.
    08 Pause
    09 FOR /f %%%%i IN (C:\TEMP\longlst.$$$) DO %JOB%  %%%%i
    10 GOTO EXIT
    11 :ERROR
    12 echo Missing C:\TEMP\LONGLST.$$$
    13 :EXIT
    14 Pause
    The variable JOB in the above template could be adapted to any type of task.

    * Expand the menu entry, in case it contains sub entries.

    You may now navigate in the "9" branch (where you've created sripts that know how to deal with a list of files) simply by pressing "9" repeatedly. Examples of such entries (which must start with a "9") could be:

     9 Upload tagged files
     9 Mail tagged files
     9 GREP tagged files
     9 Identify all identical files and generate a report
     9 Send all .PS files to Distiller to generate .PDF versions
     9 Concatenate tagged files and copy them to Clipboard

    F12,Alt+V Upgrade running ZTW.EXE from ztwNNNNN.zip
    Description When you obtain a ZTree update in the form of a ztw15178.zip file (rather than the .EXE installer version), place it in #ZThome and use this macro to upgrade to the new version. The result will be a fresh version called ZTW.EXE (v1.51.78) and a renamed one called ZTW_v1.51.77.EXE, both running.
    There are many ways to accomplish this upgrade, but this approach tries to do most of the work from within ZTree using its programming features and keystroke economy.
    Scope: FILE view with ztwNNNNN.zip selected. Split mode may be on or off.
    Origins: 1
    Code
    F9,HOME,CTRL_RIGHT,$,RET,1,RET,ESC,ALT_F5,CTRL_T,CTRL_E,.,RET,y,ESC,
    |,END,BKSP,BKSP,BKSP,ZTW.EXE,RET,o,STOP
    F9,HOME,CTRL_RIGHT Go to F9 top item and make sure at least the first level of the menu is expanded
    $,RET,1,RET Search for the first item starting with '$' and expand it. It is recommended you have only one such item in your menu. This is your "library" of small routines that you can call from any macro using the above "syntax". Within this branch locate the first item starting with '1'. Again, you should have only one such item in this branch. Execute it. This item contains:
    1 Rename currently active ZTW.EXE to ZTW_#ZTversion.EXE
    -----------------------------------------------------------------
    01 :: Purpose: Rename currently active ZTW.EXE to ZTW_version.EXE
    02 REN #ZThome\#ZTexe ZTW_#ZTversion.EXE
    Note: Obtaining the version ID of the currently running ZTW.EXE is possible via a very expensive and problematic (it does not work with paths with spaces) shell command:
    for /f "tokens=2 delims= " %%a in ('%#ZThome%\ZTW.EXE /^? ^| find "(c)"') do ren %#ZThome%\ZTW.EXE ZTW_%%a.EXE
    hence using the #ZTversion token makes much more sense.
    ESC Exit F9
    ALT_F5,CTRL_T
    CTRL_E,.,RET,y
    ESC
    Open the selected archive (ztwNNNNN.zip), tag all files and extract them to #ZThome. The 'y' will overwrite all files with their new versions from the archive. If you would like to preserve these files (typically, BETA.TXT, ZTW.HLP, ZTW_CFG.EXE), you must do this before running this macro. Note that the currently running ZTW.EXE is the only file (locked by the OS) that cannot be overwritten, which is why we first had to rename it to ZTW_vNNNNN.EXE. The currrent versions of Windows allow this renaming.
    |,END,BKSP,BKSP,BKSP
    ZTW.EXE,RET
    We are still in #ZThome, so we should be able to locate the new ZTW.EXE by deleting the "*.*" mask end entering its name in the Prompted spell search mode.
    o,STOP Open the new ZTW.EXE in another ZTree instance. At your convenience, Alt+TAB back to the old version and Quit from it. The sooner the better -- to avoid history ZTW.HST stomping!

    More Examples

    01 Multiple string searches (Version 1)
    Description ZTree allows searching for a single string only (which was exploited in another example). To search files for multiple strings requires coding a macro. In this example, we'll search all .BAT files in the current directory that contain at least one of the following srings: "CALL", "XCOPY" and "FORMAT". However, this macro cannot be stored and used reliably in the history or in an external file. Due to lack of a directive like IF_TAGS (and hence no checking), it must not be run blindly. Its main "loop" will need to be recalled from the history and edited repeatedly.
    Scope: FILE view. Split mode may be on or off.
    Origins: 1
    Code
    f,*.BAT,
    CTRL_T,CTRL_S,CALL,ENTER,CTRL_I,t,CTRL_F4,
    CTRL_T,CTRL_S,XCOPY,ENTER,CTRL_I,t,CTRL_F4,
    CTRL_T,CTRL_S,FORMAT,ENTER,CTRL_I,t,CTRL_F4,
    ENTER,ENTER,CTRL_I,t
    f,
    *.BAT
    ENTER
    Select only *.BAT files
    CTRL_T
    CTRL_S
    CALL
    ENTER
    Tag all files and search them for string "CALL". Hopefully, this will result in some files remaining tagged.
    CTRL_I,t
    CTRL_F4
    Invert tags. The files in which "CALL" was not found will be tagged. Show only tagged files, thus reducing the set of files being displayed.
    CTRL_T
    CTRL_S
    XCOPY
    ENTER
    search all tagged files for string "XCOPY". Hopefully, this will result in some files remaining tagged.
    CTRL_I,t
    CTRL_F4
    Invert tags. The files in which "XCOPY" was not found will be tagged. Show only tagged files, thus reducing the set of files being displayed.
    CTRL_S
    FORMAT
    ENTER
    search all tagged files for string "FORMAT". Hopefully, this will result in some files remaining tagged.
    CTRL_I,t
    CTRL_F4
    Invert tags. The files in which "FORMAT" was not found will be tagged. Show only tagged files, thus reducing the set of files being displayed.
    ENTER,ENTER Go to directory view and then come back to File view. This will undo the effect of Ctrl+F4, i.e., all the files will be displayed, including those that we were pushing out of the display. The latter will all be untagged.
    CTRL_I,t Invert tags for the last time. This will tag files in which one or more of the three strings exist.
    02 Multiple string searches (Version 2)
    Description This version will perform the same task, with a minor side-effect: it will not preserve the current Split mode. It's shown here also to illustrate the power of merged tags.
    Scope: FILE view. Split mode may be on or off.
    Origins: 1
    Code
    f,*.BAT
    UNSPLIT,SPLIT
    CTRL_T,CTRL_S,CALL,CTRL_F6
    CTRL_T,CTRL_S,XCOPY,CTRL_F6
    CTRL_T,CTRL_S,FORMAT,CTRL_F6
    TAB,UNSPLIT,CTRL_F4
    f
    *.BAT
    ENTER
    Select only *.BAT files
    UNSPLIT
    SPLIT
    Force a Split with the current directory in both panes.
    CTRL_T,
    CTRL_S
    CALL
    Tag all files and search them for string "CALL". Hopefully, this will result in some files becoming tagged.
    CTRL_F6 Merge tags, i.e., the tags in the active pane will be replicated in the other one.
    CTRL_T
    CTRL_S
    XCOPY
    Tag all files and search them for string "XCOPY". Hopefully, this will result in some files becoming tagged.
    CTRL_F6 Merge tags, i.e., the tags in the active pane will be replicated (and appended to those) in the other one.
    CTRL_T
    CTRL_S
    FORMAT
    Tag all files and search them for string "FORMAT". Hopefully, this will result in some files becoming tagged.
    CTRL_F6 Merge tags, i.e., the tags in the active pane will be replicated (and appended to those) in the other one.
    TAB Switch to the other pane; this is where the tags were accumulated.
    UNSPLIT Revert to single pane mode
    CTRL_F4 Display only tagged files i.e., those in which one (or more) of the 3 strings was found.
    03 Jump to last destination
    Description This macro jumps to the last directory that was used in an operation like Copy or Mirror. It illustrates the use of retreiving and then copying and pasting the user's most recent input.
    Scope: FILE view. Split mode may be on or off.
    Origins: 1
    Code
    ESC,ESC,ALT_M,F3,CTRL_INS,ESC,\,SH_INS,ENTER,ENTER
    ESC,ESC Make sure ZTree is in DIR view
    ALT_M Pretend that we want to perform the Mirror operation
    F3
    CTRL_INS
    Recall the last destination directory specified by the user, and insert it into the Clipboard
    ESC Abort the Mirror operation -- we only wanted to pick from its short-term memory
    \
    SH_INS
    Launch Treespec and paste in the last destination from the Clipboard
    ENTER Terminate the Treespec input
    ENTER Switch to File view
    04 Substituting drives
    Description The SUBST shell command is useful for creating virtual drives from a directory branch such as C:\WORK\MUSIC\MIDI. This macro will make this easy, and also allow the user to choose the drive letter. Of course, the user must know which drive letters are free. An enhanced, automated, version of this could be coded using a batch file or an item in the F9 menu. The purpose of this example is actually to illustrate the clever use of line editing a "template" macro by sending arrow keycodes.
    Scope: FILE view. Split mode may be on or off.
    Origins: 1
    Code
    x,CTRL_BKSP, SUBST x: %2:%3, HOME,RIGHT,RIGHT,RIGHT,RIGHT,RIGHT,RIGHT,RIGHT
    x
    CTRL_BKSP
    Launch the shell and clear the input field completely
    SUBST x:
    %2:%3
    Type in the DOS command, specifying the current disk and directory branch as the root of the virtual drive
    HOME Jump to the start of the input field; the cursor will be on the first "S" in "SUBST"
    RIGHT
    ...RIGHT
    Move the cursor seven times to the right; it should stop on the "x". The user can now type in a letter for the virtual drive, Z, for example, and press Enter
    05 Substituting spaces with underscores in file names (@SPC2UNDER.ZTM)
    Description Replacing spaces with dashes or underscores in file names is often needed for easier file manipulation and more portable names in multi-platform environments. This macro will locate all such files in the current branch and ask for confirmation before renaming each matching file. It illustrates the power of the internal Rename masks and functions that eliminate the need for specialized external programs or scripts.
    Scope: FILE, DIR and Autoview views. Split mode may be on or off.
    Code
    ESC,ESC,f,"* *.*" "*.* *",ENTER,*,b,CTRL_T,CTRL_R,F4," "_"N|" "_"E,ENTER
    ESC,ESC Make sure ZTree is in DIR view
    f,"* *.*"
    "*.* *"
    ENTER
    Select all files that have a space somewhere in the name or the extension.
    *,b Expand the branch and show it as a flat list of the newly selected files
    CTRL_T
    CTRL_R
    Tag all files and start the Rename function dialog
    F4 It is recommended to enable the confirmation dialog when renaming files. F4 will enable it *if* it is currently disabled via the Alt+F10 CO4D:

    D Rename protection (Confirm/Attributes) None

    If Confirm is enabled, remove F4 from this macro, because it will reverse this option! In other words, this macro is not 100% portable -- align it with your Configuration Options first! The (proposed) macro directive CONFIRM_ON|OFF would solve this problem.

    " "_"N|
    " "_"E
    Specify the Find and Replace commands that will perform the substitution in the N(ame) and E(xtension) parts of the file name. This could be coded more simply with " "_"B, which substitutes spaces with underscores in B(oth) parts of the file name in one go.
    ENTER Launch the Rename command. If you have selected confirmation, your screen will look similar to this. If not, the renaming will happen automatically.
    06 In Split mode, clone the other pane in the active pane (Treespec)
    Description Force SPLIT mode and DIR view with identical directory and drive context in both panes.
    Scope: FILE and DIR views. Split mode may be on or off, but the macro only makes sense if there are two panes with different contexts.
    Origins: Ben.Kent@aspelle.com
    Code
    SPLIT,TAB,\,ALT_UP,ESC,TAB,\,F3,SH_ESC
    SPLIT,TAB Ensure Split is in effect and switch to the other pane.
    \,ALT_UP
    ESC
    Invoke Treespec and put the current treespec on the Treespec history list. Then quit Treespec.
    TAB
    \,F3
    Return to the original pane and invoke Treespec, choosing the last treespec used.
    SH_ESC Accept the treespec without actually logging the directory.
    07 In Split mode, clone the other pane in the active pane (clipboard)
    Description Force SPLIT mode and DIR view with identical directory and drive context in both panes. Unlike the previous macro, this one uses the clipboard as a mechanism for storing and retrieving treespec information. The side effect is that the clipboard will be overwritten.
    Scope: FILE and DIR views. Split mode may be on or off.
    Origins: Ben.Kent@aspelle.com
    Code
    SPLIT,TAB,\,CTRL_INS,ESC,TAB,\,CTRL_BKSP,SH_INS,SH_ESC
    SPLIT,TAB Ensure Split is in effect and switch to the other pane.
    \,CTRL_INS
    ESC
    Invoke Treespec and put the current treespec on the clipboard. Then quit Treespec.
    TAB
    \,CTRL_BKSP
    Return to the original pane and invoke Treespec, then clear the input string.
    SH_INS
    SH_ESC
    Paste from the clipboard and accept the treespec without actually logging the directory.
    08 In Split mode, clone the other pane's directory in the active pane (keeps drive)
    Description Force SPLIT mode and DIR view with identical directory, if it exists, in both panes. Similar to the above macros, but allows leaving the drive letter intact. This makes sense only in cases where the same directories exist on both drives, otherwise, a random directory will be selected. For example, if many disks contain the \Data\Backup\Daily directory, this macro may simplify navigation when performing repetitive operations.
    Scope: FILE and DIR views. Split mode may be on or off.
    Origins: Ben.Kent@aspelle.com
    Code
    SPLIT,TAB,\,CTRL_INS,ESC,TAB,r,CTRL_BKSP,SH_INS,HOME,DEL,DEL,CTRL_INS,ESC,
    F12,SEMI,COMMA,CTR,L_BKSP,COMMA,SH_INS,COMMA,SH,_ESC,COMMA,F,12,COMMA,
    U,P,COMMA,D,EL,COMMA,E,SC,COMMA,E,SC,RET
    SPLIT,TAB Ensure Split is in effect and switch to the other pane.
    \,CTRL_INS
    ESC
    Invoke Treespec and put the current treespec on the clipboard. Then quit Treespec.
    TAB
    \,CTRL_BKSP
    Return to the original pane and invoke Treespec, then clear the input string.
    r,CTRL_BKSP
    SH_INS
    Paste the treespec into the Renama prompt.
    HOME
    DEL,DEL
    Delete the drive letter part.
    CTRL_INS
    ESC
    Copy to the clipboard and leave the Rename dialog.
    F12
    SEMI,COMMA
    CTR,L_BKSP
    COMMA,SH_INS
    COMMA,SH,_ESC
    COMMA,F,12
    COMMA,U,P
    COMMA,D,EL
    COMMA,E,SC
    COMMA,E,SC
    Invoke the Macro dialog -- yes, macros can be embedded! However, the COMMA separator gets a somewhat special treatment! This temporary macro will look as shown below and will do the actual work. It will then be deleted from the history (because it's meaningless without its calling parent macro):
                   ;          Invoke Treespec, same as \
                   CTRL_BKSP  Clear
                   \dir\dir\  The directory that was pasted in using the SH_INS
                   SH_ESC     Accept the treespec without logging the directory
                   F12        Fire up the macro input
                   UP         Invoke Macro history to do a clean up
                   DEL        Delete the temporary macro from the history
                   ESC        Exit the history
                   ESC        Exit the Macro dialog
                   
    RET Execute the temporary macro.
    09 Check all files in a branch for readability
    Description This macro searches all files in a branch for a non-existent string. This assures that every byte of every file will be read. The files that remain tagged will be those with a potential problem. Note that some system files (SOFTWARE, SECURITY, SAM, DEFAULT, etc.) will not be readable, which is normal.
    Scope: DIR or FILE view. Split mode may be on or off.
    Code
    ESC,ESC,*,b,CTRL_T,CTRL_s,[z_z_z_z_z_z],ENTER,STOP,Branch only
    ESC,ESC Make sure ZTree is in DIR view
    *,b Log the branch and show all files in the branch
    CTRL_T
    CTRL_S
    [z_z_z_z_z_z]
    ENTER
    Tag all files and search them for a string that is unlikely to exist in any of the files. This should untag all files, because no hits will be reported. However, some tagged files may still be present, not because they contain the string, but because they could not be read for various reasons.
    To show any tagged files still left, press Ctrl+Enter. The user should then examine them to determine why they were not readable/accessible.
    10 Check all files on a drive for readability
    Description This macro is a variant of the preceding macro, except that all files on a disk drive are searched for a non-existent string.
    Scope: DIR or FILE view. Split mode may be on or off.
    Code
    ESC,ESC,HOME,*,b,CTRL_T,CTRL_s,[z_z_z_z_z_z],ENTER,STOP,Entire drive
    ESC,ESC Make sure ZTree is in DIR view
    HOME,*,b Jump to drive root, log the entire drive and show all files in the branch
    CTRL_T
    CTRL_S
    [z_z_z_z_z_z]
    ENTER
    Tag all files and search them for a string that is unlikely to exist in any of the files. This should untag all files, because no hits will be reported. However, some tagged files may still be present, not because they contain the string, but because they could not be read for various reasons.
    To show any tagged files still left, press Ctrl+Enter. The user should then examine them to determine why they were not readable/accessible.
    11 PUSH/POP (Saving/Restoring) the Windows clipboard
    Description This macro demonstrates how the ZTree history feature can be used to temporarily save and then restore the Windows clipboard. This allows ZTree to run a complex task that requires the global Windows clipboard (an editor, as in this example), yet leave it intact. This is technically known as a PUSH/POP operation.
    Scope: FILE view, with at least one tagged file. Split mode may be on or off.
    Origins: 1 2
    Code
    x,CTRL_BKSP,SH_INS,ALT_UP,ESC,CTRL_INS,o,t,CTRL_INS,w,ESC,
    x,CTRL_BKSP,C:\ZTW\tde.bat /TST,SH_INS,UP,CTRL_INS,ESC,CTRL_RET,STOP
    x,CTRL_BKSP Enter eXecute command window and clear the command line
    SH_INS Paste original Clipboard into the command line
    ALT_UP Save command line (original Clipboard) to history. This is known as PUSH (on a stack).
    ESC Exit eXecute command window
    CTRL_INS Start Insert to Clipboard command
    O Set nO-path option
    t Insert tagged file names to Clipboard
    CTRL_INS Start Insert to Clipboard command
    w Set With-path option back on
    ESC Exit Insert to Clipboard (No insert)
    x,CTRL_BKSP Enter eXecute command window and clear the command line
    C:\ZTW\tde.bat
    /TST
    Place TDE editor command on command line. Of course, this can be any other command line or GUI application that accepts a list of files as input.
    SH_INS Add tagged-file list from Clipboard to command line
    UP Open History window to last entry (original Clipboard)
    CTRL_INS Insert original Clipboard contents back into Clipboard
    DEL,ESC Delete this entry from the history; no need to clutter it with some random contents! We just did a POP (from the stack). Exit History window
    CTRL_RET Run editor on tagged files
    12 Create F9 script from current file's contents (@COPY2F9.ZTM)
    Description This macro creates an F9 script at the very top of the currently active F9 database. This may come handy when migrating many .BAT files from the file system to ZTree's highly flexible and sophisticated program launcher and task organizer. Hundreds of files could thus easily be moved to a database in a few seconds.
    Scope: DIR or FILE view. Split mode may be on or off.
    Code
    ESC,ESC,RET,CTRL_INS,F,F9,HOME,ALT_A,SH_INS,RET,ALT_E,L,SH_INS,RET,ESC,ESC,[UP],STOP
    ESC,ESC,RET
    CTRL_INS,F
    Grab current file's full filespec. If you find the full path too long for your item's description, use N instead of F to copy only the name.ext part.
    F9,HOME
    ALT_A,SH_INS
    RET
    Go to currently active Application Menu database's top and create a new item there. Give it the name of the current file's full filespec.
    ALT_E,L
    SH_INS,RET
    ESC,ESC
    Edit the newly-created item by Load-ing file contents into the script body. Leave F9; we are now back in the File Window.
    [UP],STOP Once back in the File Window, move the selector up to the next file. This is optional; the benefit is that you are now ready to hit Alt+F12 to load the newly-selected file into F9, without having to navigate to it. Note that the logic of adding the items puts the new item on the top, as on a stack. The items will appear in the order that is reverse from that shown in File Window. If many files are to be copied to F9, the trick is to carefully sort or otherwise prepare the files, then select the bottom file and then let the macro work upwards.
    13 Prefix filename with its date string (@Prefix_with_yyyymmdd.ztm)
    Description This macro renames current name.ext to yyyymmdd_name.ext.
    Scope: DIR or FILE view. Split mode may be on or off.
    Code
    ESC,ESC,RET,f,TAB,TAB,TAB,TAB,TAB,_,LEFT,LEFT,LEFT,BKSP,
    LEFT,LEFT,BKSP,HOME,DEL,CTRL_INS,ESC,r,HOME,SH_INS,RET,DOWN
    ESC,ESC,RET
    f,TAB,TAB
    TAB,TAB,TAB
    Use Filespec to cycle to current file's modification date string, '=yyyy-mm-dd'. The string will differ depending on the date display format chosen by the user.
    Note: It may seem more efficient to reach the date string with a single BTAB instead of five TAB's. However, if new values to the cylce are added in the future, the macro will no longer work!
    _,LEFT,LEFT
    LEFT,BKSP,LEFT
    LEFT,BKSP
    HOME,DEL
    Append '_' to the string and edit out all '-' characters. Remove the leading '='. In this example, the string should now look like 'yyyymmdd_'.
    CTRL_INS,ESC Insert the string into the Clipboard and exit the Filespec dialog.
    r,HOME,SH_INS
    RET,DOWN
    Start the Rename dialog and paste in the 'yyyymmdd_' in front of the proposed new file name. Execute Rename and advance the selector to the next file. This makes it easier to apply the macro to a large number of files by simply auto-repeating Alt+F12.
    Note: The Rename command (ZTW.HLP, section 3.3.1.16) provides extensive date- and time-related tokens that can do much more than this example macro.
    14 Untouch file date and time
    Description This macro sets the file written date to the created date (then moves down the list ready for the next file).
    Scope: FILE view. Split mode may be on or off.
    Origins: 1
    Code
    n,F4,TAB,F4,F4,F4,RET,DOWN
    n,F4 Invoke the STAMP File: dialog and change to the created timestamp (from the default written)
    TAB Store the created timestamp value in the to: prompt
    F4,F4,F4 Cycle to the written timestamp -- the one we want to modify
    RET,DOWN Execute the command and move down to next file
    Contents

    Updated: 20070529
    Copyright 2007 vujnovic@free.fr. All rights reserved.