Path is too long.

Welcome Forums General PowerShell Q&A Path is too long.

This topic contains 4 replies, has 4 voices, and was last updated by

 
Participant
8 months, 1 week ago.

  • Author
    Posts
  • #84082

    Participant
    Points: 1
    Rank: Member

    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.

  • #84089

    Participant
    Points: 144
    Helping Hand
    Rank: Participant
  • #84101

    Participant
    Points: 1
    Rank: Member

    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...

  • #84145

    Participant
    Points: 0
    Rank: Member

    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

    .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
    
  • #95792

    Participant
    Points: 0
    Rank: Member

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

The topic ‘Path is too long.’ is closed to new replies.