Rickson
Rickson

Reputation: 1090

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.

Upvotes: 2

Views: 1374

Answers (3)

uffe hellum
uffe hellum

Reputation: 187

In PowerShell, it's safe and easy:

    PS> $folders = Get-ChildItem
    # filter $folders as needed 
    PS> $folders | ForEach-Object { tf workfold /cloak $_.Name }

Upvotes: 1

Rickson
Rickson

Reputation: 1090

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

Upvotes: 1

jessehouwing
jessehouwing

Reputation: 115037

With some creative Batch processing, you can probably combine tf dir . and tf workfold /cloak. But there is no standard way to chain these command together without parsing the output from tf dir.

It's probably easier to do with Powershell and the TFS client object model. Use the static Workstation.Current property to find the connection settings Workstation.GetWorkspaceInfo(path) .ServerUri, from there use the VersionControlServer.GetWorkspace method, to grab the workspace and then call the Workspace.Cloak method to cloak the items you found using VersionControlServer.GetItems method.

An example that comes quite close can be found here:

Upvotes: 2

Related Questions