# Path is too long

**URL:** <https://forums.powershell.org/t/path-is-too-long/9697>\
**Category:** PowerShell Help\
**Created:** [November 13, 2017, 1:14am UTC](https://forums.powershell.org/t/path-is-too-long/9697 "2017-11-13T01:14:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pavelk](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@pavelk](https://forums.powershell.org/u/pavelk)\
**Post date:** [November 13, 2017, 1:14am UTC](https://forums.powershell.org/t/path-is-too-long/9697/1 "2017-11-13T01:14:44Z")

</div>

Hi,  
I found out that part of my script’s copying (using Copy-Item) are failing due to following problem:  
_The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters._

Indeed - I had too long path sometimes.  
Tried to use robocopy, but it is copying whole directory when ,according to my flow, I need only few specific files from the directory.  
I implemented another idea - to do a mapping for longest part of the path. But in spite of the fact that I am instructing Copy-Item to use the mapping - it still fails and in the error message I see same full path. Like it is ignoring mapping…

Any ideas what to do here ?

Thanks.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [November 13, 2017, 1:36am UTC](https://forums.powershell.org/t/path-is-too-long/9697/2 "2017-11-13T01:36:18Z")

</div>

LongPathsEnabled = 1

[https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/](https://www.howtogeek.com/266621/how-to-make-windows-10-accept-file-paths-over-260-characters/)

---

<div class="post-metadata">

**Author:** ![pavelk](https://avatars.discourse-cdn.com/v4/letter/p/bbe5ce/32.png) [@pavelk](https://forums.powershell.org/u/pavelk)\
**Post date:** [November 13, 2017, 2:47am UTC](https://forums.powershell.org/t/path-is-too-long/9697/3 "2017-11-13T02:47:30Z")

</div>

Thanks for the link.  
But nope - it did not work! ☹  
May be because my long my long paths are , actually, a paths to remote machines aka “\remotemachine\d$\bla-bla…”

But unfortunately it did not help…

---

<div class="post-metadata">

**Author:** ![worlock](https://avatars.discourse-cdn.com/v4/letter/w/c77e96/32.png) [@worlock](https://forums.powershell.org/u/worlock)\
**Post date:** [November 13, 2017, 9:33am UTC](https://forums.powershell.org/t/path-is-too-long/9697/4 "2017-11-13T09:33:07Z")

</div>

There are a couple things you can try. The 1st one would be to use the literalpath argument and prefix your UNC path with "\?\UNC" so your path above would be:

```
"\\?\UNC\remotemachine\d$\bla-bla.."
```

More info on this can be found here: [https://msdn.microsoft.com/en-us/library/aa365247.aspx](https://msdn.microsoft.com/en-us/library/aa365247.aspx)

.Net 4.6.2 or higher should support long file names. Make sure you have that version to use long file names nativly in powershell.

You can also use robocopy to copy specific files.

```
ROBOCOPY \\Server1\reports \\Server2\backup *.jpg *.bmp
```

---

<div class="post-metadata">

**Author:** ![thomas-lee-2](https://avatars.discourse-cdn.com/v4/letter/t/e495f1/32.png) [@thomas-lee-2](https://forums.powershell.org/u/thomas-lee-2)\
**Post date:** [March 13, 2018, 5:17am UTC](https://forums.powershell.org/t/path-is-too-long/9697/5 "2018-03-13T05:17:12Z")

</div>

I suggest that you use LongPathTool, its an amazing tool, google it and will solve your problem.

---

<div class="post-metadata">

**Author:** ![Austin\_H](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/austin_h/32/4523_2.png) [@Austin\_H](https://forums.powershell.org/u/Austin_H)\
**Post date:** [March 28, 2024, 12:20pm UTC](https://forums.powershell.org/t/path-is-too-long/9697/7 "2024-03-28T12:20:09Z")

</div>

Closed on March 28, 2024, 12:20pm UTC


