Search code examples
if-statementmakefiledirectoryexistsrmdir

Makefile Windows -- remove directory if exists


I am trying to port a Makefile to Windows (using GNU Make). I am having trouble with removing directories. I found this question (Delete a directory and its files using command line but don't throw error if it doesn't exist) on how to conditionally remove directories, but I get an error trying to use that solution, translating approximately to The use of ""doc\html"" is syntactically impermissible in this context

The snippet causing it is this:

if exists "doc\html\" rmdir /Q /S doc\html

I also tried

cmd /c if exists "doc\html" cmd /c rmdir /Q /S doc\html

and

cmd /c if exists "doc\html\" cmd /c rmdir /Q /S doc\html.

I also tried rmdir /Q /S doc\html 2>nul. That works kind of. The error gets redirected, but Make still throws an error and stops.

How can I make this work?


Solution

  • the command is exist not exists. There is a typo in the thread I linked...