Check path length in Windows hierarchy?

Discussion in 'NZ Computing' started by KiwiBrian, Oct 5, 2005.

  1. KiwiBrian

    KiwiBrian Guest

    Is there a utility or program that I can point at a top level folder in a
    hierarchy and it will tell me of any files whose total path-length including
    file-name exceeds a predefined figure?
    It appears that Windows allows this situation to be created, thus ensuring
    some unpredictable side-effects, none of them good.
    I have not been able to find any way of checking a current existing
    situation, which seems a bit bizarre.
    TIA
    Brian Tozer
     
    KiwiBrian, Oct 5, 2005
    #1
    1. Advertisements

  2. KiwiBrian

    Harry Guest

    find / | awk 'length($0}>255{print $0}'
     
    Harry, Oct 5, 2005
    #2
    1. Advertisements

  3. KiwiBrian

    KiwiBrian Guest

    Thanks Harry.
    What would I have to do to run this on a Windows XP SP2 PC?
    Brian Tozer
     
    KiwiBrian, Oct 5, 2005
    #3
  4. KiwiBrian

    Harry Guest

    Install gnu stuff.
    Have a nice day.
     
    Harry, Oct 5, 2005
    #4
  5. KiwiBrian

    Malcolm Guest

    Malcolm, Oct 5, 2005
    #5
  6. KiwiBrian

    Alan Guest

    Hi,

    If it was me, I'd just use excel as being quick and simple, but
    obviously you would need to have that available.

    Alan.

    --
    The views expressed are my own, and not those of my employer or anyone
    else associated with me.

    My current valid email address is:



    This is valid as is. It is not munged, or altered at all.

    It will be valid for AT LEAST one month from the date of this post.

    If you are trying to contact me after that time,
    it MAY still be valid, but may also have been
    deactivated due to spam. If so, and you want
    to contact me by email, try searching for a
    more recent post by me to find my current
    email address
     
    Alan, Oct 5, 2005
    #6
  7. KiwiBrian

    Mark C Guest

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

    Get gawk here:
    http://unxutils.sourceforge.net
     
    Mark C, Oct 5, 2005
    #7
  8. KiwiBrian

    KiwiBrian Guest

    Hi Alan.
    I have Excel available on the PC under discussion.
    Could you elaborate on exactly how I can use it to achieve my objective?
    TIA
    Yours hopefully.
    Brian
     
    KiwiBrian, Oct 6, 2005
    #8
  9. KiwiBrian

    Alan Guest

    Hi Brian,

    Open a new workbook, and paste this sub into a new standard module in
    the VB Editor (watch out for wrapping in the news posting):

    +-+-+-+-+-+-+-+-+-+-+-+-+

    Sub IndexFiles()

    ' To use, select cell A1 (say) in an empty worksheet, and run this
    ' code.
    ' When it completes, you should have a full path listing of all files
    ' and folders in the named directory and sub-directories.

    SearchPath = InputBox("Enter the path to search", "Folder?")

    With Application.FileSearch

    .LookIn = SearchPath
    .FileType = msoFileTypeAllFiles
    .SearchSubFolders = True
    .Execute

    End With

    cnt = Application.FileSearch.FoundFiles.Count

    For i = 1 To cnt

    rng = "A" & i

    Range(rng).Value = Application.FileSearch.FoundFiles.Item(i)

    Next i

    End Sub

    +-+-+-+-+-+-+-+-+-+-+-+-+


    Go to A1 in an empty worksheet and run the macro above.

    Enter a path you want to check such as:

    C:\Temp

    It will list the full path and filename of each file in that directory
    and all sub-directories as text strings in A1 down.

    Bear in mind that a worksheet in excel only has 65536 rows so if you
    do this for a folder with 70,000 files it'll fall over - in that case
    do it for sub-folders one at a time.

    Once you have the file listings, enter a formula in B1 thus:

    =LEN(A1)

    Copy that down as far as the list extends and it will tell you the
    total path length for each file.

    You could then sort by column B in descending order to see the longest
    paths first.


    Post back if you need more detail on any of that.

    HTH,

    Alan.


    --
    The views expressed are my own, and not those of my employer or anyone
    else associated with me.

    My current valid email address is:



    This is valid as is. It is not munged, or altered at all.

    It will be valid for AT LEAST one month from the date of this post.

    If you are trying to contact me after that time,
    it MAY still be valid, but may also have been
    deactivated due to spam. If so, and you want
    to contact me by email, try searching for a
    more recent post by me to find my current
    email address
     
    Alan, Oct 6, 2005
    #9
  10. KiwiBrian

    Harry Guest

    Gee that is really simple. Clever of MS to provide such a powerful
    and user-friendly tool! So simple!

    BTW you can get a copy of gawk.exe, on its own, from nearly everywhere
    on the internet. You could also do the same thing with perl.exe, viz:

    dir /b/s | perl -ne 'print $_ if length($_) > 255;'

    Doing it in excel is lame.
     
    Harry, Oct 6, 2005
    #10
  11. KiwiBrian

    Alan Guest

    Indeed - I totally agree.

    In my opinion Excel is one of the reasons that so few businesses will
    move away from MS Windows in the foreseeable future, simply because
    there is nothing to compare with it's flexibility and power.

    Sure, if you just want a flashy calculator, you can use Open Office or
    Star Office or something, but they don't come near the power of
    Excel's VBA object model / capabilities.

    Personally, I am all for the Linux / OSS model - I love that it gives
    us so much choice and mostly for free compared to the extortionate
    prices for Office.

    However, in most business environments Excel and Access rule for the
    actual end users who need to use the business data stored in the
    enterprise DBs and there is no marginal cash cost to using them since
    they are already there.
    Personally, I do not know anyone who would have access to gawk.exe or
    Perl.exe outside of software developers etc. I'm sure some people do,
    but at the same time I cannot think of anyone at any of my clients who
    *doesn't* have excel available.

    At the end of the day, the OP needs a solution, and it appears that
    this gives them one that they can implement quickly, easily, and
    safely.
    {Shrug}

    Took me about 3 mins to do when I tried it and that's *all* that
    really matters in the end isn't it?

    What would be the benefit of spending 15 mins finding, downloading,
    installing (maybe), and working out how to use, say, perl or gawk,
    when they can do the above in 5 mins, get the answer they need, and
    move on to something else that needs to be done.

    The OP wanted a solution that works for them and that does I believe.

    Plus, no need to search for and download software that might have
    nasties in it either.

    Each to his own.

    Alan.


    --
    The views expressed are my own, and not those of my employer or anyone
    else associated with me.

    My current valid email address is:



    This is valid as is. It is not munged, or altered at all.

    It will be valid for AT LEAST one month from the date of this post.

    If you are trying to contact me after that time,
    it MAY still be valid, but may also have been
    deactivated due to spam. If so, and you want
    to contact me by email, try searching for a
    more recent post by me to find my current
    email address
     
    Alan, Oct 6, 2005
    #11
  12. KiwiBrian

    Harry Guest

    It took me as long as it took to type the answer. About 10 seconds.
    Because the next time it will be a lot faster and easier.

    The sort of person who has a problem with path lengths isn't going
    to be your average Excel user. They are going to be a lot closer to
    the software and hardware than that. Therefore they should equip themselves
    with some tools that do the job more quickerly and more better (in MS-speak).
    Excel is so fantastic at doing the job that the OP had to ask in
    a newsgroup how to do it! LOL.
    Sure! Only had to download and setup nntp client software and post
    a question in a newsgroup to get the solution. LOL!
     
    Harry, Oct 6, 2005
    #12
  13. KiwiBrian

    Adam Guest

    Out of interest, I downloaded the utils and ran the gawk.exe from a
    DOS shell (in the wbin directory, Brian!).

    Turns out you have a typo:

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

    The curly brace after the first $0 should be a plain old right
    bracket.

    I did a test using:

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

    and it spewed out thousands of them .. at great speed!

    Adam.
     
    Adam, Oct 6, 2005
    #13
  14. The OP is using windows, even if he didn't already have an nntp client
    setup, MS provide a handy one called Outlook Express(which the OP was
    using)...

    The way you describe it, he would also have to install and configure a
    browser before using your solution.
     
    Dave - Dave.net.nz, Oct 6, 2005
    #14
  15. KiwiBrian

    Alan Guest

    But it would have taken the OP much longer to find it and get it
    working - your focus is on you, not the OP.
    It is a very common issue for standard users when writing to CD if
    they use the (Joliet?) standard which restricts total path length for,
    I guess, compatibility.

    I'm not suggesting that *you* would want to use excel, but if you
    walk into an office and try to get the users to use command line
    tools, you'll quickly find it ain't gonna happen. They will use the
    tools they are already familar with and that means MS Office.


    I'm done with this unless the OP has further queries.

    Alan.


    --
    The views expressed are my own, and not those of my employer or anyone
    else associated with me.

    My current valid email address is:



    This is valid as is. It is not munged, or altered at all.

    It will be valid for AT LEAST one month from the date of this post.

    If you are trying to contact me after that time,
    it MAY still be valid, but may also have been
    deactivated due to spam. If so, and you want
    to contact me by email, try searching for a
    more recent post by me to find my current
    email address
     
    Alan, Oct 6, 2005
    #15
  16. KiwiBrian

    Harry Guest

    Oh really!?
     
    Harry, Oct 7, 2005
    #16
  17. KiwiBrian

    Harry Guest

    But the OP had to "type a question".
    Though the OP might apparently loath using a command-line, like having
    to type something, the OP was perfectly prepared to open up OE
    and type something!

    The OP might be perfectly prepared to learn how to use Excel, and perhaps
    how to use the English language, but the OP is not prepared to learn
    relatively simpel commands.

    What is the difference between typing a macro in a spreadsheet and
    typing a command in a window?
    Huh?
     
    Harry, Oct 7, 2005
    #17
  18. KiwiBrian

    Harry Guest

    Quite right! My very first typo. Congratulations.
    That wassn't very difficult was it?
    Or perhaps opening up Excel and typing in a whole lot of
    formulae would be easier?
     
    Harry, Oct 7, 2005
    #18
  19. the "command in a window" that he was offered meant he had to download
    some stuff, the macro in excell he didn't.
    thought that might go over your head.
     
    Dave - Dave.net.nz, Oct 7, 2005
    #19
  20. T'was the Thu, 06 Oct 2005 22:22:25 +1000 when I remembered Harry
    That's not true. I've had files written to my computer by programs
    that have had massive names. Then when I tried to copy those files to
    a CD, I get problems.

    This is a problem "average Excel users" face.
     
    Waylon Kenning, Oct 7, 2005
    #20
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.