Locate all Files on D:\ with Paths longer than 258 Charaters

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jwinfl
Posts: 89
Joined: 16 Aug 2017, 12:37

Locate all Files on D:\ with Paths longer than 258 Charaters

20 Jul 2021, 06:43

I have an old laptop that runs xp.
Lightning destroyed my desktop motherboard, cpu and powersupply so I needed my old laptop but its files were several years old.
When I tried to copy all files from my desktop's (w10) drive D: to my laptop, xp would not copy many of them because xp said the file names were illegal (the full path was too long).
Copying is a pain because xp stops copying files, shows an error message, and you have to guess which files were not copied, etc.
After some testing, I found that xp on my laptop would only copy paths up to 258 visible characters, over 258 resulted in error messages.
I want to locate these long path files and save their full paths to a file so I can shorten them or delete them, so that if I ever need to copy D: to my laptop in the future it won't take hours.
I started writing a script but read that atleast one ahk file command ignores files with paths that are over 259 characters which pretty much defeats the purpose of the script.
Hopefully someone out there knows an easy way to get ahk to find all file paths over 258 long.
Any help would be appreciated.
User avatar
mikeyww
Posts: 26885
Joined: 09 Sep 2014, 18:38

Re: Locate all Files on D:\ with Paths longer than 258 Charaters

20 Jul 2021, 06:56

You could use Loop, Files and then StrLen. FastCopy is also quite good as an alternative.
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Locate all Files on D:\ with Paths longer than 258 Charaters

23 Jul 2021, 04:28

Most commands support long paths in AutoHotkey v1.1.31 and later, but the OS still has limits. To get around them on XP, you must use a Unicode version of AutoHotkey and the \\?\ prefix, as in:

Code: Select all

Loop Files, \\?\D:\*, FDR
    if StrLen(A_LoopFileFullPath)-4 > 258
        MsgBox % A_LoopFileFullPath
I would just use robocopy, but as it's not included in XP, you would need to find a copy somewhere.
jwinfl
Posts: 89
Joined: 16 Aug 2017, 12:37

Re: Locate all Files on D:\ with Paths longer than 258 Charaters

24 Jul 2021, 08:04

lexikos,
thank you for you post
your code appears to work fine.
i would have thanked you sooner but selecting "Notify me when a reply is posted" never notified me of any postings.
SarahSi
Posts: 1
Joined: 14 Oct 2021, 04:51

Re: Locate all Files on D:\ with Paths longer than 258 Charaters

14 Oct 2021, 04:59

I prefer to shorten the pathname to avoid this issue, but if you have many paths, many tools can handle this issue easily like the Long Path Tool, Gs Richcopy 360, Long Path Fixer....etc.
Also I sea the code by lexikos, very helpful

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, Fredrik F, garry, maxkill, RandomBoy, ShatterCoder and 399 guests