rmdir
Finding empty directories in Python
import os if not os.listdir(dir): os.rmdir(dir) LBYL style. for EAFP, see mouad’s answer.
Cannot delete a file even when logged in as an Administrator [closed]
Just because you are an admin doesn’t automatically mean you have rights. Are you running PowerShell as an elevated user (UAC)? Have you checked the permissions of the files in question just to be sure? Are the files in use perhaps? Although if that was the case I would expect access is denied. Have you … Read more
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
How do I remove an empty folder and push that change?
The short answer: You can’t push changes to directories (added, removed, etc.) because Git does not track directories on their own. According to the FAQ: Currently the design of the git index (staging area) only permits files to be listed, and nobody competent enough to make the change to allow empty directories has cared enough … Read more
How to remove files and directories quickly via terminal (bash shell) [closed]
rm -rf some_dir -r “recursive” -f “force” (suppress confirmation messages) Be careful!
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