Is there a python file eraser?

Asked By 460 points N/A Posted on -
qa-featured

Hello fellows,

Is there a python file eraser? My friend is using python programming language for building an important program or system; she asks me if I have any idea about the python file eraser. I want to help my friend to research about this. Share with me your answers and ideas.

Regards,

Benjamin.

SHARE
Best Answer by Allen Kenneth
Answered By 0 points N/A #92380

Is there a python file eraser?

qa-featured

Hello Benjamin,

Your question is really unclear. Do you mean a python program that erases files or a program that erases python files? Whatever the case may be, this link will shed more light on the issue:

http://bleachbit.sourceforge.net/forum/question-about-shredding-files-using-python

Here's a python file eraser software:

http://www.freedownloadmanager.org/download/python-file-eraser-5476948.html

I hope your friend find this information.

Best Answer
Best Answer
Answered By 0 points N/A #92381

Is there a python file eraser?

qa-featured

Hello Benjamin,

Your question is somewhat unclear. But assuming that you were trying to find some method to delete files using Python, here are a couple of methods you can follow.

You can do use the remove () function from the module 'OS'
 
import os                           
os.remove('Path/To/File.ext')

Or try this code below.


#!/usr/bin/env python

import os
 
def nukedir(dir):
    if dir[-1] == os.sep: dir = dir[:-1]
    files = os.listdir(dir)
    for file in files:
        if file == '.' or file == '..': continue
        path = dir + os.sep + file
        if os.path.isdir(path):
            nukedir(path)
        else:
            os.unlink(path)
    os.rmdir(dir)
 
nukedir("/home/mb/test");

Hope this will fix it.

 

Login/Register to Answer

Related Questions