visual-studiotfstf-clicloaking

TFS: Cloaking multiple elements from command line


Suppose we have a folder $/myProject/myFolder on the TFS server which contains some files and sub-folders.

Is there any possibility to iteratively cloak every element under this folder (not recursively) using the tf.exe command line utility?

I can't simply cloak the root folder $/myProject/myFolder because I need to decloak some of its elements afterwards which seems only to be possible, if each element has been cloaked independently.

In the end, I want to achieve that all elements below a specific root folder are cloaked except of some predefined ones.


Solution

  • Comparing to the worst pieces of source code I have ever written, this one is definitely under the top three.

    However, after doing almost every possible batch beginner's mistake, the code below finally does what I need (considering the limitation mentioned in the code).

    It will cloak all folders and files below the predefinded root folder myServerFolder. myServerFolder must have the following syntax including the final slash: $/myProject/myFolder/.

    If anyone has a good idea to simplify the code or has found a bug please edit it directly or let me know.

    Again, thank you for your support!

    @echo off
    setlocal enabledelayedexpansion
    
    REM Limitation: Folder and file names must not end with ")" nor start with "$"
    set myServerFolder=$/myProject/myFolder/
    
    REM Process Folders
    for /f "Tokens=*" %%a in ('tf.exe dir %myServerFolder%') do (SET TEXT=%%a& SET SUBSTR_A=!TEXT:~-1!& SET SUBSTR_B=!TEXT:~0,1!& (IF "!SUBSTR_A!" NEQ ":" IF "!SUBSTR_A!" NEQ ")" (IF "!SUBSTR_B!" EQU "$" (set currParam=!TEXT:~1!&(tf.exe workfold /cloak "%myServerFolder%%!currParam!")))))
    
    REM Process Files
    for /f "Tokens=*" %%a in ('tf.exe dir %myServerFolder%') do (SET TEXT=%%a& SET SUBSTR_A=!TEXT:~-1!& SET SUBSTR_B=!TEXT:~0,1!& (IF "!SUBSTR_A!" NEQ ":" IF "!SUBSTR_A!" NEQ ")" (IF "!SUBSTR_B!" NEQ "$" (set currParam=!TEXT!&(tf.exe workfold /cloak "%myServerFolder%%!currParam!")))))
    
    PAUSE