Moving Multiple Files to Restructure TFS

So today I was tasked with restructuring one of our projects in TFS. It was a standalone web application that was now needing to have a console application added to handle automated invoicing.

I had already moved several folders by hand one by one, I realized there has to be a better way.

And, of course, this problem was answered for me several years ago by the wonderful stackoverflow community.

Well, not really knowing how the wildcard would work with my already moved files, and not really wanting to mess things up, I decided that I would do things a little more explicitly.

So I used the following command in my Visual Studio Command Prompt (VSCP) to get all of the files in the directory:

tf dir "$/Project/dev"

This output a bunch of folders and files, as such:

$/Project/dev:
$App_Code
$Bin
$Folder01
$Folder02
$Folder03
About.aspx
About.aspx.cs
Project.sln
Contact.aspx
Contact.aspx.cs
Default.aspx
Default.aspx.cs
Default_original.aspx.exclude
Disclaimer.aspx
Disclaimer.aspx.cs
FAQ.aspx
FAQ.aspx.cs
Global.asax
Glossary.aspx
Login.aspx.cs.exclude
Login.aspx.exclude
LogOut.aspx
LogOut.aspx.cs
PrivacyPolicy.aspx
PrivacyPolicy.aspx.cs
Registration.aspx
Registration.aspx.cs
Resources.aspx
Resources.aspx.cs
Robots.txt
Site.master
Site.master.cs
Web.config

I then pasted that into one of my favorite text editors (Notepad++), and ran the following Find/Replace regular expression command

Find what: ^(.*)$
Replace with: tf rename "$/Project/dev/\1" "$/Project/dev/Web/\1"

This then gave me the following as output:

tf rename "$/Project/dev/About.aspx" "$/Project/dev/Web/About.aspx"
tf rename "$/Project/dev/About.aspx.cs" "$/Project/dev/Web/About.aspx.cs"
tf rename "$/Project/dev/Contact.aspx" "$/Project/dev/Web/Contact.aspx"
tf rename "$/Project/dev/Contact.aspx.cs" "$/Project/dev/Web/Contact.aspx.cs"
tf rename "$/Project/dev/Default.aspx" "$/Project/dev/Web/Default.aspx"
tf rename "$/Project/dev/Default.aspx.cs" "$/Project/dev/Web/Default.aspx.cs"
tf rename "$/Project/dev/Default_original.aspx.exclude" "$/Project/dev/Web/Default_original.aspx.exclude"
tf rename "$/Project/dev/Disclaimer.aspx" "$/Project/dev/Web/Disclaimer.aspx"
tf rename "$/Project/dev/Disclaimer.aspx.cs" "$/Project/dev/Web/Disclaimer.aspx.cs"
tf rename "$/Project/dev/FAQ.aspx" "$/Project/dev/Web/FAQ.aspx"
tf rename "$/Project/dev/FAQ.aspx.cs" "$/Project/dev/Web/FAQ.aspx.cs"
tf rename "$/Project/dev/Global.asax" "$/Project/dev/Web/Global.asax"
tf rename "$/Project/dev/Glossary.aspx" "$/Project/dev/Web/Glossary.aspx"
tf rename "$/Project/dev/Login.aspx.cs.exclude" "$/Project/dev/Web/Login.aspx.cs.exclude"
tf rename "$/Project/dev/Login.aspx.exclude" "$/Project/dev/Web/Login.aspx.exclude"
tf rename "$/Project/dev/LogOut.aspx" "$/Project/dev/Web/LogOut.aspx"
tf rename "$/Project/dev/LogOut.aspx.cs" "$/Project/dev/Web/LogOut.aspx.cs"
tf rename "$/Project/dev/PrivacyPolicy.aspx" "$/Project/dev/Web/PrivacyPolicy.aspx"
tf rename "$/Project/dev/PrivacyPolicy.aspx.cs" "$/Project/dev/Web/PrivacyPolicy.aspx.cs"
tf rename "$/Project/dev/Registration.aspx" "$/Project/dev/Web/Registration.aspx"
tf rename "$/Project/dev/Registration.aspx.cs" "$/Project/dev/Web/Registration.aspx.cs"
tf rename "$/Project/dev/Resources.aspx" "$/Project/dev/Web/Resources.aspx"
tf rename "$/Project/dev/Resources.aspx.cs" "$/Project/dev/Web/Resources.aspx.cs"
tf rename "$/Project/dev/Robots.txt" "$/Project/dev/Web/Robots.txt"
tf rename "$/Project/dev/Site.master" "$/Project/dev/Web/Site.master"
tf rename "$/Project/dev/Site.master.cs" "$/Project/dev/Web/Site.master.cs"
tf rename "$/Project/dev/Web.config" "$/Project/dev/Web/Web.config"

As you may have noticed, I took out the solution file for this project, since it should reside outside of the project file.

I ran the rename commands in my VSCP, and voila. Files were moved.

Now that the files were moved, I had to update the solution file to accommodate for the newly moved folder. Hopefully you’ve had some experience in doing this, but it’s really not that hard if you haven’t before.

Simply locate the “Project” line, as well as any “PhysicalPath” properties for the web application directory, and update them to be “Web\”. Save the file, and then open it as usual.

I hope this has helped you.

Thanks and code on!
RJ

RJ writes custom Windows and Web applications using the Microsoft .NET framework, and enjoys solving problems with code, often while listening to a techno soundcloud stream. He hopes to one day write an application that many businesses will use.

Twitter 

Leave a Reply

Your email address will not be published. Required fields are marked *