What is the complete path? Since you don't start your path with for instance C:\
on Windows or /
on Linux you are trying to remove a directory relative to the current working directory. This probably does not evaluate to the directory you are trying to delete.
If you want to access your $dirname
variable inside your function you will have to use the global keyword. But better practice is to pass the directory as a variable to your function.
Also, as a matter of good practise, you should have the function implementation before trying to call it. Usually, it doesn't matter, but there are a few exceptions, particularly when the existence of a function is conditional on some other code being executed.