Search code examples
qtqt4qmakedel

Delete directory contents with qmake during build


I would like QMAKE_CLEAN to empty/delete a data directory in my build directory. I already have it clear out all of the DLLs from the build directory like so:

win32: {
    Debug: {
        QMAKE_CLEAN += $$slasher("$${OUT_PWD}/debug/*.dll")
    } else {
        QMAKE_CLEAN += $$slasher("$${OUT_PWD}/release/*.dll")
    }
}

and that works just fine.

However, when I try to delete the entire contents of a directory like so:

QMAKE_CLEAN += $$slasher("Q:/stuff/*.*")

It fails to work. I looked in the Compile Output window and saw this text:

Q:\stuff\*.*, Are you sure (Y/N)? 

Why does this prompt show up and how can I get past it?

FYI, The `slasher' function is just a convenience function to turn forward slashes to backslashes on a Windows machine.


Solution

  • Apparently the Windows del command requires a prompt when using the global wildcard. You can suppress this prompt by adding the /Q flag to the delete call in windows like this:

    QMAKE_CLEAN += "$$slasher("Q:/stuff/*.*") /Q"
    

    It's sketchy at best, but it works. If anyone knows another way in Qt4, I'd be happy to hear it.

    Edit I just found out that if you invoke this syntax twice in the PRO file, the compiler will complain. My workaround is to move the /Q to the very end of the PRO file in its own QMAKE_CLEAN call. It benignly confuses qmake by causing an additional call to del /Q during clean, but appears to work as expected.

    For example...

    QMAKE_CLEAN += "$$slasher("Q:/stuff1/*.*")"
    QMAKE_CLEAN += "$$slasher("Q:/stuff2/*.*")"
    QMAKE_CLEAN += /Q
    

    ...will delete the entire contents of stuff1 and stuff2.