Why does QDir create a directory that (apparently) doesn't exist and cannot be deleted?



  • I am currently writing a short program using Qt that will take a text file with directory details, and will create those directories.

    The text file looks something like this:
    @Computers
    Computer Science
    Mathematical Foundations
    Mathematical Logic
    Number Theory
    Graph Theory
    Game Theory
    Coding Theory
    Algorithms and Data Structures
    Algorithms
    Data Structures... // and so on@

    The number of tabs decide the hierarchy of the directory, similar to the python language in a way.

    Anyway, after reading this file, the program creates a directory listing as follows:
    @"E:/EBooks/Library/Computers"
    "E:/EBooks/Library/Computers/Computer Science"
    "E:/EBooks/Library/Computers/Computer Science/Mathematical Foundations"
    "E:/EBooks/Library/Computers/Computer Science/Mathematical Foundations/Mathematical Logic"
    "E:/EBooks/Library/Computers/Computer Science/Mathematical Foundations/Number Theory"
    "E:/EBooks/Library/Computers/Computer Science/Mathematical Foundations/Graph Theory"
    "E:/EBooks/Library/Computers/Computer Science/Mathematical Foundations/Game Theory"
    "E:/EBooks/Library/Computers/Computer Science/Mathematical Foundations/Coding Theory"
    "E:/EBooks/Library/Computers/Computer Science/Algorithms and Data Structures"
    "E:/EBooks/Library/Computers/Computer Science/Algorithms and Data Structures/Algorithms"
    "E:/EBooks/Library/Computers/Computer Science/Algorithms and Data Structures/Data Structures"@

    I then use this with QDir::mkpath() to make the folder. The only thing is the Algorithms folder, and all its parent folders are undeletable and it tells me that this folder no longer exists, even though I can see it in Explorer and I move files to the folder.

    I did a little checking and after looking at the input text file I found that the "Algorithms " entry actually had a space at the end of it. Removing the space got rid of the problem. I was using the whitespace to figure out where a folder belongs, which is why I didn't run simplified() on it. Is this a bug, or maybe I'm going about it the wrong way?



  • bq. The only thing is the Algorithms folder, and all its parent folders are undeletable and it tells me that this folder no longer exists, even though I can see it in Explorer and I move files to the folder.

    It is unclear what the "it" that tells you a folder no longer exists is. Windows explorer perhaps?

    If you could not delete the lowest directory name "Algorithms " then you would be unable to delete any of its parent directories either. If Windows Explorer cannot delete a file/folder that Windows created then I would call that a bug in Explorer and not in Qt. It is not, however, something I can reproduce here.



  • From Microsoft Dev Center:

    bq. Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not. However, it is acceptable to specify a period as the first character of a name. For example, ".temp".

    Source: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#file_and_directory_names


Log in to reply
 

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