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.
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%
[sourcecode language=”text”]
@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
[/sourcecode]
So this is purely an example: use it as a head-start to create your own.
–jeroen






Leave a Comment