19

We are using TFS 2010 and facing a problem with deleting a folder inside of a solution in Visual Studio.

In the latest version of checked-in code, the directory in question has files in it.

One of the developers decided to move the files in that directory to another location within the solution. He then tried to delete the old folder but go the following error:

This operation cannot be completed. 
You are attempting to remove or delete a source-controlled item where the item is either exclusively locked elsewhere or otherwise unable to be deleted from source control.

Does anyone know what the problem is with trying to do this and is there a way to get around it?

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
thiag0
  • 2,199
  • 5
  • 31
  • 51

2 Answers2

28

You cannot delete a folder that has pending changes on any of its children (including if any of those children are being moved out of the folder - they're still children until that changeset is checked in.)

You'll have to do this in two steps: first, move the children out of the folder and check those changes in, then delete the folder as a separate changeset.

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • 7
    +1. To elaborate: **Never** mix edit, rename and delete operations in TFS - It can cause problems even for one developer, and major problems if your changes require merging into another branch or another developer's workspace. TFS 2010 is much more robust in this regard than 2008 and 2005, but it's still a really bad idea to overlap rename/delete operations with edits. When doing rename/delete, try to ensure you're the only user changing those files and check in each change separately. – Jason Williams May 24 '11 at 21:56
  • 1
    I'm not sure I'd go that far. I check in changesets regularly that contain lots of refactoring (edit / add / delete / etc.) Could you discuss more the problems that you're having? – Edward Thomson May 25 '11 at 13:03
  • I have to admit I do a bit of mixing between check-ins at times and while I feel a little dubious about it (given my scary history with VSS) I haven't really had problems so far. I did have one folder that would not delete but followed George Witte's suggestion (as responded on this question) and solved the problem easily. – Jason Snelders Oct 11 '11 at 07:38
  • Facing the same situation, doing a merge from another branch where the delete and rename happened, probably in 2 steps. Is there an easy way to exclude the deletion, but proceed with the move/rename? Excluding "to be deleted" parent folder also excludes the children that require to be moved. It would nice not having to proceed manually with this move when performing a merge between branches. – Louis Aug 27 '14 at 21:19
9

If the folder you want to delete exists on your local machine, just add a new file to the folder from within the Visual Studio IDE (it doesn't matter what type of file). Then you should be able to delete the folder from within VS.

If the folder was deleted from your local machine, create a new one with the same name and then follow the above steps.

George Witte
  • 151
  • 1
  • 4
  • Perfect! Thank you George. I had a folder I couldn't delete locally on either of my development machines (and wasn't in source control). I added a file; checked in; deleted the folder and all good. – Jason Snelders Oct 11 '11 at 07:35
  • Thanks - This worked for me also - I needed to delete a folder, but didn't want to check in. And yes, the problem had arisen because I moved newly files with pending checkins out of the folder and it was not empty. To fix, I added a file; "undo" the Add File pending change; deleted the folder and file. – Joseph Gabriel Mar 13 '12 at 21:50
  • Awesome. Not being able to remove that folder was really annoying. Great find. SO never lets me down! :) – Mike U Feb 10 '14 at 20:11