How to check existence of a folder with python and then remove it?

Python’s os.rmdir() only works on empty the directories, however shutil.rmtree() doesn’t care (even if there are subdirectories) which makes it very similar to the Linux rm -rf command. import os import shutil dirpath = os.path.join(‘dataset3’, ‘dataset’) if os.path.exists(dirpath) and os.path.isdir(dirpath): shutil.rmtree(dirpath) Modern approach In Python 3.4+ you can do same thing using the pathlib module … Read more

Delete directory with files in it?

There are at least two options available nowadays. Before deleting the folder, delete all its files and folders (and this means recursion!). Here is an example: public static function deleteDir($dirPath) { if (! is_dir($dirPath)) { throw new InvalidArgumentException(“$dirPath must be a directory”); } if (substr($dirPath, strlen($dirPath) – 1, 1) != “https://stackoverflow.com/”) { $dirPath .= “https://stackoverflow.com/”; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)