Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Is this usage a common case QDir::rmdir(".") ?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 765 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Thuan_FirelightT Offline
    Thuan_FirelightT Offline
    Thuan_Firelight
    wrote on last edited by
    #1

    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.

    jsulmJ 1 Reply Last reply
    0
    • Thuan_FirelightT Thuan_Firelight

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Thuan_Firelight Why not just?

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

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

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • Thuan_FirelightT Offline
        Thuan_FirelightT Offline
        Thuan_Firelight
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved