3

is there anyway to create a directory where the path is longer than 260 characters? I am using powershell and my code is [io.Directory]::CreateDirectory(\\fileshare\$FolderStructure) but it stops creating the folders when the path length becomes grater than 260 characters. I tried adding \\?\ to the start but it didn't that failed

davetherave
  • 1,147
  • 3
  • 10
  • 15
  • 1
    This is a [well](http://blogs.msdn.com/b/bclteam/archive/2007/02/13/long-paths-in-net-part-1-of-3-kim-hamilton.aspx) [known](http://blogs.msdn.com/b/bclteam/archive/2007/03/26/long-paths-in-net-part-2-of-3-long-path-workarounds-kim-hamilton.aspx) [problem](http://blogs.msdn.com/b/bclteam/archive/2008/07/07/long-paths-in-net-part-3-of-3-redux-kim-hamilton.aspx). My advice would be to make folder names shorter, or the hierarchy less deep. I've seen folder structures with paths longer than 260 characters, and it's insane what some people pick as folder (or file) names at times. – Ansgar Wiechers Jul 30 '15 at 18:30
  • There is a [PowerShell User Voice Item for this issue](https://windowsserver.uservoice.com/forums/301869-powershell/suggestions/11685975-long-path-support). – TravisEz13 Jun 15 '16 at 05:55

1 Answers1

1

As already mentioned in a comment, this is a well known limitation (see here for the Bug description and here for past workarounds). However, Microsoft has addressed this issue now in .NET 4.6.2 together with the Windows 10 anniversay update: See here for the latest documentation about the partial removal of the file path limitation. At the moment it does not make sense to give a working example as Microsoft changes the details nearly every month. Everyone reading this answer will need to look at the latest documentation.

bergmeister
  • 949
  • 2
  • 10
  • 16
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Bhargav Rao Nov 05 '16 at 21:51
  • Thanks for your suggestion. I updated the answer to provide more references and details but as Microsoft keeps changing the implementation of this brand new feature, there is no better answer other than: 'There is a new way of handling it but please refer to the latest documentation as it changes frequently at the moment' – bergmeister Nov 06 '16 at 20:15