QDirIterator - Seems to skip some files?



  • I've been scratching my head for a while now as I can't figure out why QDirIterator seems to skip some files when iterating.

    For example, in one folder I have 341 files in different subfolders (right click folder -> properties) but my code counts it to 324. Some other folders it works just fine on.

    I really can't figure out what is wrong so any help would be appreciated!

    (I'm on Windows 7 if that matters)

    My code:
    @int fileCount = 0;

    QDirIterator it("C:\mydir", QDirIterator::Subdirectories);

    while (it.hasNext())
    {
    it.next();

    QFileInfo fi = it.fileInfo();

    if (fi.isFile())
    {
    fileCount++;
    qDebug() << it.fileName();
    }
    }

    qDebug() << "Total file count: " + QString::number(fileCount);@


  • Moderators

    Do you (count|ignore) '.' and '..' in both cases?



  • How are you counting the 341 files you think you have? Are you counting each directory as a file also? (Your code does not)

    Why don't get your code to print out the things it thinks are not count-worthy? You will probably quickly see a pattern.



  • [quote author="Tobias Hunger" date="1351148265"]Do you (count|ignore) '.' and '..' in both cases?[/quote][quote author="ChrisW67" date="1351150511"]How are you counting the 341 files you think you have? Are you counting each directory as a file also? (Your code does not)[/quote]To count the files in the folder to have something to compare to I simply right click it and go to properties, there it says "341 files, 39 folders".
    [quote author="ChrisW67" date="1351150511"]Why don't get your code to print out the things it thinks are not count-worthy? You will probably quickly see a pattern.[/quote]I tried and it prints out the foldernames, "." and ".." only.



  • So there are no sub directories under C:\mydir but you are telling me that Windows says there are 39. Not looking in the same place methinks.

    If your application does not have a manifest then you may be the victim of Windows Vista/7's helpful "UAC Virtualization":http://msdn.microsoft.com/en-us/library/windows/desktop/bb756960.aspx : designed to help legacy apps that write to prohibited locations like the root of C:. The legacy app, once it triggers a virtualized folder only ever sees that faked folder, but Windows Explorer will see the real one.

    Try a small test folder some where you know you can write to safely.



  • [quote author="ChrisW67" date="1351206697"]So there are no sub directories under C:\mydir but you are telling me that Windows says there are 39. Not looking in the same place methinks.[/quote]No, there are both files and subdirectories in this folder (39 subdirectories in fact). So there must've been a misunderstanding somewhere. :)
    [quote author="ChrisW67" date="1351206697"]If your application does not have a manifest then you may be the victim of Windows Vista/7's helpful "UAC Virtualization":http://msdn.microsoft.com/en-us/library/windows/desktop/bb756960.aspx : designed to help legacy apps that write to prohibited locations like the root of C:. The legacy app, once it triggers a virtualized folder only ever sees that faked folder, but Windows Explorer will see the real one.

    Try a small test folder some where you know you can write to safely.[/quote]I made a test folder, created subfolders and put some empty text files and such in those and it worked just fine. Then I changed to another folder on another drive with a few more files, and the file count was off with about 75 files.

    However, I found a folder which says in the properties window that it contains 28 files. But when I open it in the explorer there's only 23 files - no hidden files. But I found out that was because explorer was set to "hide protected systemfiles".

    So I guess there's no error in the code then. :)

    Sorry for my english by the way.



  • [quote author="xiit" date="1351211174"]No, there are both files and subdirectories in this folder (39 subdirectories in fact). So there must've been a misunderstanding somewhere. :)[/quote]
    I don't think so. You tell me that Windows Explorer counts "341 files, 39 folders" but that the Qt code counts only 324 files looking recursively at the 'same' folder. When the Qt lists the things that it does not match, which should include each of the 39 folders because they are not files, you claim it only lists "." and "..". That is what I was basing my input on.

    Glad you are happy with your resolution, but it seems that Explorer should be showing fewer files than the Qt code in this case.



  • This is an old thread but I want to post in anyway because I have the "same" problem.

    When I iterate over the directory entries with QDirIterator it shows fewer files than QDir::entryList(). I am searching on a network path from a Windows 7 PC.

    @
    QDir rd(rootDir);
    qDebug() << rd.entryList();
    @

    lists more files than (I know that I am skipping the first)

    @
    QDirIterator it( rd );
    while( it.hasNext() ) {
    qDebug() << it.next();
    }
    @

    Any Idea?



  • This is even more strange because entryList() uses QDirIterator to prepare the first list.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.