Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,501
    Thanks
    86
    Thanked 13 Times in 12 Posts

    Searching for long file names

    While I was copying files from one folder to another, I got a warning that there were filenames included that were longer than 256 characters. Rather than dealing with each one at that time, I just continued the copying.

    Is there a process or program that I can use to scan a folder and find all the files with "too long" names, and move them so that I can then deal with them -- rename perhaps -- later?

    Regards,
    Chuck Billow
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,771
    Thanks
    402
    Thanked 1,549 Times in 1,404 Posts
    Chuck,

    You really have file names that are that long? Are you sure it isn't the File spec, e.g. drive\path\filename.ext?
    The only work around I know is to flatten your tree out (fewer levels) or to copy at a lower level. HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,501
    Thanks
    86
    Thanked 13 Times in 12 Posts
    RG, no, it's the whole path, and in fact I never actually saw a problem, so I guess I just shouldn't worry about it.

    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

  4. #4
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,672
    Thanks
    58
    Thanked 1,064 Times in 989 Posts
    Windows doesn't have a length issue, but Windows Explorer does. The easiest way to fix the issue is to rename (shorten) the folder names that contain the offending files until you can work with the files themselves. Alternatively use Robocopy to move the files to a shorter path.

    cheers, Paul

  5. #5
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,771
    Thanks
    402
    Thanked 1,549 Times in 1,404 Posts
    Paul,

    Both MS & I disagree.
    Maximum Path Length Limitation

    In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\some 256-character path string<NUL>" where "<NUL>" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.)
    Here's the full article on MS Tech Net.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  6. #6
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,672
    Thanks
    58
    Thanked 1,064 Times in 989 Posts
    RG, I've used / fixed many a long path in Windows, but it may be because I was working with servers / 64bit software.

    cheers, Paul

  7. #7
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,771
    Thanks
    402
    Thanked 1,549 Times in 1,404 Posts
    Paul,

    Yes, the hardware/software can be very different on servers.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  8. #8
    Super Moderator Rick Corbett's Avatar
    Join Date
    Dec 2009
    Location
    South Glos., UK
    Posts
    2,800
    Thanks
    125
    Thanked 767 Times in 619 Posts
    Copy/paste the following into a Notepad file and save it as FilepathChecker.vbs:

    Code:
    Dim oShell
    Set oShell = CreateObject("Wscript.Shell")
    
    Const FOR_READING = 1
    strFolder = InputBox("Enter the filepath (local or UNC) you wish to query, e.g. C:\Windows or \\server\share$\folder")
    'strFolder = "C:\Windows"
    
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    'Create a file to pipe the results to
    LogFileName = oShell.SpecialFolders("Desktop") & "\FilePathLength.txt"
    Set fsHandle = objFSO.OpenTextFile (LogFileName,8,True)
    
    'Recurse through folders and get the full path of files, inc. in sub-folders
    Set objFolder = objFSO.GetFolder(strFolder)
    fsHandle.Writeline objFolder.Path
    Set colFiles = objFolder.Files
    For Each objFile In colFiles
      fsHandle.Writeline "(" & Len(objFile.Path) & " Chrs) " & objFile.Path
    Next
    ShowSubFolders(objFolder)
     
    Sub ShowSubFolders(objFolder)
      Set colFolders = objFolder.SubFolders
      For Each objSubFolder In colFolders
        fsHandle.Writeline objSubFolder.Path
        Set colFiles = objSubFolder.Files
        For Each objFile In colFiles
          fsHandle.Writeline "(" & Len(objFile.Path) & " Chrs) " & objFile.Path
        Next
        ShowSubFolders(objSubFolder)
      Next
    End Sub
    
    oShell.Popup "Check the FilePathLength.txt file on your desktop.", 3, "Path length checker"
    
    Wscript.Quit()
    When you run it you'll be asked to enter a starting point (like C: or C:\Windows, etc.) When it's finished there'll be a text file on your desktop called FilePathLength.txt. In the file you will see a list of your files prefixed by the numbers of characters. Tested on Windows XP and Windows 7.

    Hope this helps...

  9. The Following 3 Users Say Thank You to Rick Corbett For This Useful Post:

    cmptrgy (2015-10-29),KenYoung (2017-03-10),RolandJS (2017-03-06)

  10. #9
    New Lounger
    Join Date
    Mar 2017
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks for vbs code!

    Many thanks for this code, it works perfectly!

  11. #10
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,771
    Thanks
    402
    Thanked 1,549 Times in 1,404 Posts
    Hey Y'all,

    For those who might be interested here's a PowerShell version with options to control mininum size reported and write to a CSV file:

    Get-LongFileNames.ps1 Get-LongFileNames.zip

    Here's the messages it puts out:

    Invalid Path:
    LFN-InvalidPathMsg.JPG

    No Files Found:
    LFNNoFIles.JPG

    Output File Location:
    LFN-FileWrittenMsg.JPG

    What the csv file looks like in excel when column B set to Wrap Text and lengthened:
    lfnexcel.JPG

    HTH
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  12. The Following User Says Thank You to RetiredGeek For This Useful Post:

    KenYoung (2017-03-10)

  13. #11
    5 Star Lounger
    Join Date
    Jan 2010
    Location
    Fort McMurray, Alberta, Canada
    Posts
    689
    Thanks
    72
    Thanked 89 Times in 84 Posts
    The thing is though, there have to be logic holes in the file name length restrictions.

    Many times over the years, I've created filenames that were too long and later I had to shorten. If the rules were fundamental, creating that filename would have been prohibited in the first place. And that includes all the path information. Therefore the issue really isn't different whether the problem is with a FQFN or just the FN.

    Yes, it happens more often when you copy from an NTFS volume to a DVD for instance. However that's because CDFS has more restrictive naming rules than NTFS.

    On this forum no more than a week ago I mentioned how I had a too-long name on NTFS and I couldn't edit the name to correct the problem. That does not involve CDFS, at all. So how come I was able to create the name with the problem in the first place?


  14. #12
    5 Star Lounger
    Join Date
    Jan 2010
    Location
    Fort McMurray, Alberta, Canada
    Posts
    689
    Thanks
    72
    Thanked 89 Times in 84 Posts
    On another note, it's fantastic to see the programmers and problem-solvers among us, coming up with solutions.


  15. #13
    WS Lounge VIP
    Join Date
    Dec 2009
    Location
    Earth
    Posts
    8,672
    Thanks
    58
    Thanked 1,064 Times in 989 Posts
    Windows doesn't have a name length restriction any more but Explorer, and possible other things, does, so a program may create long file names and then when you attempt to use them in Explorer it appears to be broken.

    cheers, Paul

  16. #14
    Silver Lounger RolandJS's Avatar
    Join Date
    Dec 2009
    Location
    Austin metro area TX USA
    Posts
    1,885
    Thanks
    108
    Thanked 143 Times in 140 Posts
    I remember reading somewhere that a total of 256 characters can be squeezed into a folder & file name "one-liner"; for lack of better technical English; I hope somebody can explain far better than I. I'm in a middle school cafeteria with noisy kids and distractions.
    Last edited by RolandJS; 2017-03-07 at 09:21.
    "Take care of thy backups and thy restores shall take care of thee." Ben Franklin revisited.
    http://collegecafe.fr.yuku.com/forum...-Technologies/

  17. #15
    Uranium Lounger CWBillow's Avatar
    Join Date
    Jul 2002
    Location
    Las Vegas, NV USA
    Posts
    6,501
    Thanks
    86
    Thanked 13 Times in 12 Posts
    Thanks to all!

    Chuck
    -------------------------------------------------
    "Good judgment comes from experience, and experience - well, that comes from poor judgment."

    ~ A(lan) A(lexander) Milne (1882-1956)- "House at Pooh Corner"

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •