Results 1 to 6 of 6

Thread: Count number of directory nesting

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Count number of directory nesting

    So, where exactly is the problem. Use QDir and use QDir::cdUp() till both are the same. You need of course to count how often you cd up. Or simply split on / and subtract one from the other.

  2. #2
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: Count number of directory nesting

    My first thought too was to count slashes, but you have to be careful about terminal slashes (that is, "/" is the last character in the string).

    Probably the best thing to do is strip or otherwise take into account any terminal slashes before doing your counting. It's not a problem if your root and target directories both end in "/" or both don't end in "/" but you'd get the wrong answer if one ended in "/" and the other didn't, as in your example.

  3. #3
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Count number of directory nesting

    So run both strings through QDir::cleanPath before counting the slashes

  4. #4
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Count number of directory nesting

    Thank to all
    Franco Amato

Similar Threads

  1. Count files of a directory
    By radu_d in forum Qt Programming
    Replies: 6
    Last Post: 27th March 2012, 03:17
  2. Count the number of rows in a QTableView
    By grub87 in forum Qt Programming
    Replies: 9
    Last Post: 28th June 2009, 16:31
  3. Dock Nesting Problem
    By blaylockr in forum Newbie
    Replies: 4
    Last Post: 14th August 2008, 13:59
  4. QDockWidget nesting problem..
    By aamer4yu in forum Qt Programming
    Replies: 6
    Last Post: 31st January 2007, 12:23
  5. count line number in text
    By Alina in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2006, 08:29

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.