The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,157 other followers

TFS: moving files using the TF.EXE command-line utility (Team Foundation System)

Posted by jpluimers on 2010/11/18

I recently needed to move around a bunch of files in TFS to a new directory structure.

Doing that from within the Visual Studio 2010 IDE was tedious, so I wrote a batch-file like below.
This batch file should also work for Team Foundation System 2005 and 2008.

  • %~dp1 fetches the drive + directory from %1.
  • %~nx1 fetches the filename + extension from %1.
  • relative target directories work better than absolute ones
  • the batch-file assumes it executes with the current directory is %sourceDirectory%

@echo off


set username=domain\username
set password=somePassw0rd

set filename=%~nx1
set sourceDirectory=%~dp1

rem strip backslash
set sourceDirectory=%sourceDirectory:~0,-1%

rem strip last 3 charachters
set targetDirectory=%sourceDirectory:~0,-3%

rem make relative directory
for /D %%d in (%sourceDirectory:~0,-3%
) do set targetDirectory=%%~nd

echo "%filename%"
echo "%sourceDirectory%"
echo "%targetDirectory%"

tf move /login:%username%,%password% %filename% ..\%targetDirectory%\%filename% 

So this is purely an example: use it as a head-start to create your own.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: