Friday, June 29, 2012

P: is for Path and is less than 260 characters

TF10128: The path contains more than the allowed 260 characters. Type or select a shorter path.

I have run into this issue a number of times over the past year for some reason engineers just want to name a project, class or solution what it is without having to think about string lengths and file systems. I like to keep my projects folder in my user profile because that's where everything else is... neat and tidy. Thankfully a solution, something that hearkens back to the of flannel, blue jeans and birkenstock sandals with socks possibly where this limitation all started.

After solving this now for the 4th time the following works the best. Take the code below paste it into notepad and change the path to your source location. Remember to keep two \\ slashes for every one in the reg file or it wont work. You will have to reboot your computer for the change to take effect.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\DOS Devices]

To solve the problem I simply add a batch file to my start up folder that creates a drive substitution.


How the characters limitation is calculated:

 Path length + 1 (separator) +
   Solution name length + 1 (separator) +
   Project name length + 1 (separator) +
   Project name length +
   80 (Reserved space)

Dude where is my admin?

  1. Create a shortcut to the batch/cmd file
  2. Right click on properties
  3. Replace the Target with: %windir%\System32\cmd.exe /c "Map Projects.cmd"
  4. Click "Advanced..."
  5. Check "Run as administrator"
This method works more reliably and allows for drive substitution on the system user (Debugging windows Service)
  1. Create a scheduled task that runs on login of your user account or system startup
  2. Set the task to run under the user you want P for
  3. Enter SUBST as the program name
  4. Instead of %USERPROFILE% use the full path
  5. Enter P: "C:\Users\{Your Account Name Here}\My Projects" in the arguments box
  6. Run the task manually if you get a 0 result you have successfully configured P