Is this usage a common case QDir::rmdir(".") ?



  • Hi,

    I am not sure if this is a potential bug or the function just wasn't meant to be used this way. but on Windows I find I am able to have an empty directory removed if I did something like QDir(<directorypath>).rmdir("."). On Mac however, this doesn't seem to work.

    Wondering how common is it to do a rmdir(".") to remove the QDir itself or do people always go 1 directory up and call rmdir with the name of the directory? I found it handy to be able to have some way to remove the directory pointed to by a QDir.


  • Moderators

    @Thuan_Firelight Why not just?

    QDir("").rmdir("<directorypath>");
    

    For me it is not common (never seen) to delete a directory like in your example.



  • I guess it's not that useful in my original example. In my actual production code, I was removing a file and I want to remove the directory the file resides in if it's the last file. So I have a QFileInfo info(<lastfile>) and I wanted to do info.absoluteDir().rmdir("."). I guess your approach could work as well.


Log in to reply
 

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