The Wiert Corner – irregular stream of stuff

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

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

    20140508-Delphi-2007--Project-Options--Cannot-Edit-Application-Title-HelpFile-Icon-Theming

    20140430-Fiddler-Filter-Actions-Button-Run-Filterset-now

    20140424-Windows-7-free-disk-space

    More Photos
  • Pages

  • All categories

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

    Join 1,317 other followers

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

Posted by Jeroen Pluimers 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.
Notes:

  • %~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

setlocal

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% 
endlocal

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

–jeroen

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 1,317 other followers

%d bloggers like this: