Question: I want to make sure that I delete required files.
I have code something like

```
dir="/some/path/"
file = "somefile.txt"
cmd_rm= "rm -rf "+dir + file
os.system(cmd_rm)

```

The `dir` and `file` values are fetched from a database. How can I make sure I never end up running `rm -rf /`? 

What things should I check before doing `rm -rf`?

Answer: 
Use `shutil.rmtree` as Dave Kirby says. If you want to delete the just the file use:

```
dir = "/some/path/" 
file = "somefile.txt" 
cmd = os.path.join(dir, file) 
shutil.rmtree(cmd) 

```

If you want to delete the directory use:

```
dir = "/some/path/" 
file = "somefile.txt"  
shutil.rmtree(dir) 

```

If the files are write protected make sure you have write permissions before you run this.
Assuming that your mentioning *rm -rf* is not just at random, but is exactly the command you need, why not just to call it? There is a lib allowing a greater integration with shell called [**sh**](https://github.com/amoffat/sh).

```
from sh import rm

path_to_delete = '/some/path'
if os.path.exists(path_to_delete):
    rm('-rf', path_to_delete)

```

PS Make sure you are not root and/or ask for user input to be extra cautious.
And, yes, smoke the man to avoid deleting a single file recursively ;)