It seems with Team Explorer, you can move individual files by right-clicking the file and choosing Move. However, you can’t do this with multiple files selected! You can move a whole folder, but that moves the entire folder and not just the files in it, so it doesn’t work to a sub-folder within that folder.
I suggested checking out the files, moving them in the workspace on his local machine and then checking them back in. I was thinking that TFS would be aware that these files have now moved and would handle this accordingly. WRONG!
We could move them and then add them as new files in the “new” location, but this would mean they lose all the history for the files.
It turns out, you can’t move files around in Source Control using Team Explorer, but you can by using the tf.exe command-line utility provided (usually found in: C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE). You’ll need to add the correct path for your computer using the DOS Set command like this:
[sourcecode language="html"]SET PATH=%PATH%;"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE"
To do this you use the rename function of the utility and provide the new location for the files, like this:
- Get the latest copy of the files that you want to move, using Team Explorer.
- Open a Command Prompt and change to the drive and path where the files you want to move currently exist.
- Move the files to the new location using the rename function of the tf.exe command-line utility like this:
[sourcecode language="html"] tf rename <files> <new_location> /lock:checkin
The following example will move all files into a sub-folder of the current folder called Video Thumbs:
[sourcecode language="html"] tf rename *.* "Video Thumbs" /lock:checkin
If you now look at the Source Control new & old folders in the workspace and you should see your files have been moved. All you have to do now is check in the changes and the files are moved!
WARNING: Using a wildcard like *.* will also move folders!
14 Comments
Is it necessary to add the /lock command?
ReplyDeleteI mean when you use the "move" option in Visual Studio it only says "rename" next the file you moved and not "lock, rename".
@Oliver:
ReplyDeleteThe /lock parameter is optional.
If this option is not specified on the command-line then the current lock status is maintained for the items.
The possible options available are: None, Checkin, Checkout
I use the Checkin so that I can confirm the changes and then check-in the move. Others can check-out the file(s) but they can't check in revisions until I release the lock.
If a file is locked by others then the lock operation will fail. Using none will remove any locks that exist.
I'd advise having a play within a temporary project (we have one I use for such 'testing') or within a folder nobody is using to discover the behaviour that suits you best.
The /lock:none was what I was looking for.
ReplyDeleteDoes adding the /lock:none command amount to the same things as completely omitting the /lock command?
@Oliver:
ReplyDeleteNo.
Using /lock:none will remove any locks that exist on the items you wish to move.
If you do not put the /lock option at all then the existing lock of the items you wish to move is not changed.
Ah ok.
ReplyDeleteThank you very much for your answers :)
Much oblige for this post. It addressed my exact problem and works like a charm!
ReplyDeleteThats grat, works fine!
ReplyDeleteThanks
Thanks a lot! It's exactly what I was looking for.
ReplyDeletethe path on a 64 bit win with 32 bit VS can be:
ReplyDeleteC:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE
Of course, no reason to change the path if you open up the Visual Studio Command Prompt (under start->Microsoft Visual Studio->Visual Studio Tools->Visual Studio Command Prompt)
ReplyDeleteI wrote a simple C# program that adds the UI facility around TFS "move" command and it works asynchronously...
ReplyDeletehttp://tfsmover.sourceforge.net/
Enjoy!
Thanks for sharing! I will give it a try sometime... :D
ReplyDeleteYou are a star! cheers mate
ReplyDeleteThe instructions are just perfect for moving files in TFS
ReplyDeleteYou are a legend! cheers mate!