Pgm for finding too long path/filenames.

Discussion in 'NZ Computing' started by KiwiBrian, Sep 9, 2005.

  1. KiwiBrian

    KiwiBrian Guest

    I am wanting a program or utility or method of checking a large hierarchy of
    folders and files and flagging somehow any that exceed the 255 character
    path/filename
    limit.
    Hoping someone can help
    TIA
    Brian Tozer
     
    KiwiBrian, Sep 9, 2005
    #1
    1. Advertising

  2. KiwiBrian

    Mercury Guest

    Nero?
    simulate writing a cd.


    "KiwiBrian" <> wrote in message
    news:dfrig9$9vg$...
    >I am wanting a program or utility or method of checking a large hierarchy
    >of
    > folders and files and flagging somehow any that exceed the 255 character
    > path/filename
    > limit.
    > Hoping someone can help
    > TIA
    > Brian Tozer
    >
    >
     
    Mercury, Sep 9, 2005
    #2
    1. Advertising

  3. KiwiBrian

    Harry Guest

    KiwiBrian wrote:

    > I am wanting a program or utility or method of checking a large hierarchy
    > of folders and files and flagging somehow any that exceed the 255
    > character path/filename
    > limit.
    > Hoping someone can help
    > TIA
    > Brian Tozer


    find /path | awk 'length($0)>255{print $0}'
     
    Harry, Sep 9, 2005
    #3
  4. KiwiBrian

    Hgaoid Guest

    On Fri, 09 Sep 2005 21:00:03 +1000, Harry <> wrote:

    >KiwiBrian wrote:
    >
    >> I am wanting a program or utility or method of checking a large hierarchy
    >> of folders and files and flagging somehow any that exceed the 255
    >> character path/filename
    >> limit.
    >> Hoping someone can help
    >> TIA
    >> Brian Tozer

    >
    >find /path | awk 'length($0)>255{print $0}'


    If you're such a smartarse, you'd check his headers:
    Microsoft Outlook Express 6.00.2900.2670

    and see your little linux command would do jack.
     
    Hgaoid, Sep 9, 2005
    #4
  5. KiwiBrian

    Mark C Guest

    Harry <> wrote in
    news::

    > KiwiBrian wrote:
    >
    >> I am wanting a program or utility or method of checking a large
    >> hierarchy of folders and files and flagging somehow any that
    >> exceed the 255 character path/filename
    >> limit.
    >> Hoping someone can help
    >> TIA
    >> Brian Tozer

    >
    > find /path | awk 'length($0)>255{print $0}'


    .... or in Windows-speak:

    dir c:\/s/b | gawk "length($0)>255{print $0}"

    Get gawk here:
    http://unxutils.sourceforge.net/

    (I note that gawk sometimes doesn't pipe ('|') well on Windows 2000,
    so you may have to use this instead:

    dir c:/s/b > dir.out
    gawk "length($0)>255{print $0}" dir.out

    Mark
     
    Mark C, Sep 9, 2005
    #5
  6. On Fri, 9 Sep 2005 20:52:37 +1200, KiwiBrian wrote:

    >I am wanting a program or utility or method of checking a large hierarchy of
    >folders and files and flagging somehow any that exceed the 255 character
    >path/filename
    >limit.
    >Hoping someone can help
    >TIA
    >Brian Tozer
    >



    Here's a C++ cmd line prog I've hastily modified to do it. It builds a
    list then dumps it to the screen. It could write the list to a file if
    you prefer. Send me an email if you want the .exe or some slight
    changes. It doesn't recurse further when it hits a directory that
    already exceeds max length. Builds with GCC. It has some stuff in it
    you don't need that I've partly commented out. It might need a
    plus/minus one correction somewhere for the length check - or maybe not.

    Graeme


    #include <string>
    #include <cstring>
    #include <iostream>
    #include <list>
    #include <vector>
    #include "windows.h"

    using std::string;
    size_t max_length;

    WIN32_FIND_DATA wfd;
    std::vector<string> max_list;

    inline bool sort_by_name_compare( const WIN32_FIND_DATA& d1,
    const WIN32_FIND_DATA& d2)
    {
    return strcmp( d1.cFileName, d2.cFileName ) < 0;
    }

    inline bool sort_by_date_compare( const WIN32_FIND_DATA& d1,
    const WIN32_FIND_DATA& d2)
    {
    return CompareFileTime( &d1.ftLastWriteTime, &d2.ftLastWriteTime ) <
    0;
    }


    void display_filename(const WIN32_FIND_DATA & fdat)
    {
    SYSTEMTIME ftime;
    std::cout << "\n " << fdat.cFileName << " ";
    if ( FileTimeToSystemTime(&fdat.ftLastWriteTime, &ftime ) )
    {
    std::cout << ftime.wYear << ' '
    << ftime.wMonth << ' '
    << ftime.wDay << ' '
    << ftime.wHour << ' '
    << ftime.wMinute << ' '
    << ftime.wSecond;
    }
    }


    void FindFiles( string& csStartFolder, bool recurse)
    {
    static WIN32_FIND_DATA wfd;
    static std::list<WIN32_FIND_DATA>::const_iterator filelist_iter;

    std::list<WIN32_FIND_DATA> filelist; // for this directory

    HANDLE hFF = 0;
    string csFile;
    string csSubPath;
    string csTgt;

    csTgt = csStartFolder + "\\*.*";
    hFF = FindFirstFile(csTgt.c_str(),&wfd);
    if (hFF == INVALID_HANDLE_VALUE)
    return;

    while (true)
    {
    if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
    {
    if ( strcmp(wfd.cFileName, ".") &&
    strcmp(wfd.cFileName, "..") )
    {
    csSubPath = csStartFolder + "\\" + wfd.cFileName;
    if ( csSubPath.length() >= max_length )
    {
    max_list.push_back(csSubPath);
    }
    else if (recurse)
    {
    FindFiles(csSubPath, recurse);
    }
    }

    /***************************************************
    if ( strcmp(wfd.cFileName, ".") &&
    strcmp(wfd.cFileName, "..") && recurse )
    {
    // recurse into the subdir:
    csSubPath = csStartFolder + "\\" + wfd.cFileName;
    FindFiles(csSubPath, recurse);
    }
    *****************************************************/
    }
    else
    {
    csFile = csStartFolder + "\\" + wfd.cFileName;
    if ( csFile.length() >= max_length )
    {
    max_list.push_back(csFile);
    }
    //filelist.push_back(wfd);
    }
    if (!FindNextFile(hFF, &wfd))
    {
    /***********
    std::cout << '\n' << csStartFolder << '\n';
    std::cout << "\n >>>>> Sorted by name <<<<<";
    filelist.sort( sort_by_name_compare );
    for ( filelist_iter = filelist.begin();
    filelist_iter != filelist.end(); ++filelist_iter )
    {
    display_filename( *filelist_iter );
    }
    std::cout << "\n\n >>>>> Sorted by date <<<<<";
    filelist.sort( sort_by_date_compare );
    for ( filelist_iter = filelist.begin();
    filelist_iter != filelist.end(); ++filelist_iter )
    {
    display_filename( *filelist_iter );
    }
    *****************/
    break;
    }
    }
    FindClose( hFF );
    }

    int main()
    {
    string s1;
    while (true)
    {
    std::cout << "\nEnter directory name :";
    std::cin >> s1;
    std::cout << '\n';
    max_length = 100;
    if (s1 != "X")
    {
    max_list.clear();
    FindFiles( s1, true);
    for (size_t k = 0; k < max_list.size() ;++k )
    {
    std::cout << max_list[k].length() << ' ' << max_list[k]
    << ' ' << std::endl;
    }
    }
    else
    { break;
    }
    }
    }
     
    Graeme Prentice, Sep 9, 2005
    #6
  7. KiwiBrian

    Allistar Guest

    KiwiBrian wrote:

    > I am wanting a program or utility or method of checking a large hierarchy
    > of folders and files and flagging somehow any that exceed the 255
    > character path/filename
    > limit.
    > Hoping someone can help
    > TIA
    > Brian Tozer


    Hi Brian,
    This bash script should do the trick:

    =========================
    #!/bin/sh

    MAX_LEN=255

    ls -1R | while read f ; do
    length=`expr length "$f"`
    if [ $length -gt $MAX_LEN ]; then
    echo "$f = $length"
    fi
    done
    =========================

    set MAX_LEN to the maximum length you want file names to be, includind their
    directory path from the current directory.

    Hope this helps,
    Allistar.
     
    Allistar, Sep 9, 2005
    #7
  8. KiwiBrian

    Harry Guest

    Hgaoid wrote:

    > On Fri, 09 Sep 2005 21:00:03 +1000, Harry <>
    > wrote:
    >
    >>KiwiBrian wrote:
    >>
    >>> I am wanting a program or utility or method of checking a large
    >>> hierarchy of folders and files and flagging somehow any that exceed the
    >>> 255 character path/filename
    >>> limit.
    >>> Hoping someone can help
    >>> TIA
    >>> Brian Tozer

    >>
    >>find /path | awk 'length($0)>255{print $0}'

    >
    > If you're such a smartarse, you'd check his headers:
    > Microsoft Outlook Express 6.00.2900.2670


    If you're such a smartarse then you'd know that gawk is available for
    Windows.

    If you're such a smartarse then you'd know that Windows filesystems can
    be viewed on Linux via Samba.

    If you're such a smartarse then you'd know you can boot up Linux and
    read Windows filesystems directly.

    If you're such a smartarse you'd understand that whatever mail client
    somebody uses doesn't mean much. I use OE quite often. But I also
    run X with Windows as window manager.

    >
    > and see your little linux command would do jack.


    You are so thick! Read Mark C's post.
     
    Harry, Sep 9, 2005
    #8
  9. KiwiBrian

    Harry Guest

    KiwiBrian wrote:

    > I am wanting a program or utility or method of checking a large hierarchy
    > of folders and files and flagging somehow any that exceed the 255
    > character path/filename
    > limit.
    > Hoping someone can help
    >


    find dir | awk 'length($0)>255{print $0}'
     
    Harry, Sep 10, 2005
    #9
  10. KiwiBrian wrote:
    > I am wanting a program or utility or method of checking a large hierarchy of
    > folders and files and flagging somehow any that exceed the 255 character
    > path/filename
    > limit.
    > Hoping someone can help


    heh, try copying them... it'll tell you.

    --
    http://dave.net.nz <- My personal site.
     
    Dave - Dave.net.nz, Sep 11, 2005
    #10
  11. KiwiBrian

    beckystorm

    Joined:
    Feb 12, 2013
    Messages:
    2
    I suggest you use a tool that shall help you with this problem especially when you tried different techniques yet still having the same problem all over again. Look for "Long Path Tool", then eventually you'll be able to manage you're folders well. Goodluck, Thanks
     
    beckystorm, Feb 12, 2013
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dadiOH
    Replies:
    1
    Views:
    1,928
    anthonyberet
    Jul 21, 2003
  2. Slartibartfast
    Replies:
    2
    Views:
    992
    John R. Baker
    Jul 22, 2003
  3. db
    Replies:
    0
    Views:
    578
  4. Martin Krag

    Long Path Tool - Fix Path Too Long Forever

    Martin Krag, Mar 31, 2011, in forum: Windows 64bit
    Replies:
    0
    Views:
    1,406
    Martin Krag
    Mar 31, 2011
  5. Martin Krag

    Long Path Tool - Fix Path Too Long Forever

    Martin Krag, Mar 31, 2011, in forum: Wireless Networking
    Replies:
    1
    Views:
    2,322
    robinst
    Dec 15, 2012
Loading...

Share This Page