Important: Please read the Qt Code of Conduct -

QMake: how to delete folder on clean on windows

  • Issue:
    I'm using windows and qmake for my project. For some of my resources, I copy some files and folders over to the output directory as a post-build step (as opposed to using the qt resource system). Then upon clean I want to also clean my resources, so I can be sure that I've refreshed my files when I'm doing a rebuild.

    For deleting files I can do something like QMAKE_CLEAN += $$PWD/Resources/*.dat

    But I cannot delete folders using QMAKE_CLEAN, it looks like it expects files only (I found this piece of documentation on
    I also found the QMAKE_DEL_TREE command, but I cannot seem to combine it with QMAKE_CLEAN. QMAKE_DEL_TREE turns into rmdir /s /q on windows, but when I add it to QMAKE_CLEAN, my forward slashes turn into backslashes (maybe because QMAKE_CLEAN expects files, I'm on windows, and it thinks it's being smart?). Obviously, this breaks the command.

    Is there a way to delete the folder incl all contents? I'm deleting stuff on a file-by-file basis now, but this does not scale well for deeper directory trees.

    Similar question (without answer) on SO

Log in to reply