2

Tried to offload some files onto an external hard drive, unfortunately because Windows is Windows: the paths are too long.

So I try:

Copy-Item "E:\" -Destination "F:\ableton_backup" -Recurse

And I get the following error:

Copy-Item: Second path fragment must not be a drive or UNC name

Surely there is a simple way to copy a bunch of files across to an external drive?

BitShift
  • 145
  • 1
  • 11
  • Can you reduce the path length of the main source folder? You need to shorten the total path. – John Mar 03 '21 at 01:23
  • Hey @John that's not really possible here... is Windows really this shit? – BitShift Mar 03 '21 at 01:31
  • You need to try to shorten the path, otherwise the problems will just get worse. – John Mar 03 '21 at 01:33
  • ok I'll try to copy the existing files/folders to the external drive at the same path length/depth, altering the path length isn't an option and tbh shouldn't be an issue at all – BitShift Mar 03 '21 at 01:52
  • can you find out the exact path that triggers the error? also, what happens if you use the `-LiteralPath` parameter instead of just throwing the source path at the cmdlet & letting it decide how to use it? – Lee_Dailey Mar 03 '21 at 02:16
  • @BitShift Check this out: https://superuser.com/questions/1119883/windows-10-enable-ntfs-long-paths-policy-option-missing/1119948#1119948 and change that reg values as listed in the **Registry Import Enabling Long Paths** section. It's likely just a Windows issue that can be iron out with that fix assuming you're running Windows 10 of course. You might try to explore Robocopy from command line which is a native Windows built in tool that might do the trick. From elevated cmd run `robocopy /?` to get some detail. – Vomit IT - Chunky Mess Style Mar 03 '21 at 03:27
  • use robocopy. it can (and will) copy files that violate many of window's rules like path length, win32 reserved word, null-terminated, etc. – Frank Thomas Mar 03 '21 at 04:56

1 Answers1

1

It's easy to solve, Windows limits file name paths to a maximum of 260 characters by default, but you can easily fix it by editing the registry, here is how to do it in PowerShell (you will need Administrator priviledges):

Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name LongPathsEnabled -Type DWord -Value 1

Restart PowerShell and you should be able to run your command without problems. (If you still can't copy the files after this tweak, restart Windows.)

Ξένη Γήινος
  • 2,824
  • 6
  • 28
  • 62
  • That is objectively incorrect, this is not a simple solution and I weep for future generations that there are ppl making such claims with reference to this abonination of an OS. However, this seems to have worked and I am very grateful for your input. Thank you. – BitShift Mar 03 '21 at 08:26
  • You accepted my answer, would you consider also give it an upvote? – Ξένη Γήινος Mar 03 '21 at 08:30
  • 1
    Heck yes I would. Thanks again! – BitShift Mar 03 '21 at 08:32