Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Delete Files Program

So this is still a work in progress. Basically it is a prompt that asks the person for their name, they input it, and then it proceeds to delete their files. I only have this project 2/3 done, so it is far from complete.

Things that need to be worked on:
  • Figure out how to delete files on computer

Here is the code:

Code
import time

input = raw_input('What is your name?:')
print '\nInitializing script...'
count = 0

while count < 100:
    if input.lower() == 'username': #enter user's name here
        print 'Proceeding to delete your hard drive'
        time.sleep(1)
        count += 1

print '\nHard drive has been deleted'
del works in windows and rm works on linux, unix, mac.

Add os to your imports and use:
os.system("del FILEPATH") or os.system("rm FILEPATH")

A simple os check in an if can choose between them.

I'm assuming you mean delete that particular users files and not everything on the harddrive, in that case its just a matter of deleting their specific user directories. On windows you would delete:
C:/Users/USERNAME
on Linux:
~/USERNAME
And maybe do a deep scan for any non-critical files attached to their username.

Your while loop also doesn't make any sense. Why would it only work for hardcoded users? Why not just confirm that the inputted username is an actual username in that if? After all it would be bad if it deleted all directories with the inputted name and someone did system32 for example.

2/3 done? More like 1/8th.

I don't mean to sound like a downer but I don't recommend making this, its a bit redundant when you can delete the user account. (The deep scan bit would be useful though)
(Nov 7, 2015 02:17 PM)SavageBoys Wrote:  del works in windows and rm works on linux, unix, mac.

Add os to your imports and use:
os.system("del FILEPATH") or os.system("rm FILEPATH")

A simple os check in an if can choose between them.

I'm assuming you mean delete that particular users files and not everything on the harddrive, in that case its just a matter of deleting their specific user directories. On windows you would delete:
C:/Users/USERNAME
on Linux:
~/USERNAME
And maybe do a deep scan for any non-critical files attached to their username.

Your while loop also doesn't make any sense. Why would it only work for hardcoded users? Why not just confirm that the inputted username is an actual username in that if? After all it would be bad if it deleted all directories with the inputted name and someone did system32 for example.

2/3 done? More like 1/8th.

I don't mean to sound like a downer but I don't recommend making this, its a bit redundant when you can delete the user account. (The deep scan bit would be useful though)

I'm open to all feedback 😁Thank you for posting your response. This is more like a troll script if anything, so it wasn't meant to do much. I do agree, 1/8th is more of a respectable number in terms of progress, still need to research about these things since I'm still starting out.

You seem very knowledgeable in Python, hope I can learn more from you 🤝
I'm more knowledgeable in Bash than Python (started not long ago), this is just one of those things that carries over.

The problem with doing this is that in Windows you are almost guaranteed to run into issues deleting certain files (in use, improper permissions, etc) and in linux you would need to run the script as the root user to get far. (and at that point all it takes is: rm -rf / anyways to delete everything on the HDD)
Don't use os.system it just makes it more complicated. See this post on SO http://stackoverflow.com/a/6996628


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by DARPANov 2, 2016 07:26 AM 3 200 Nov 2, 2016 07:26 AM
Last Post: lilo
[Shell] by ♦ [̲̅$̲̅(̲̅1000)̲̅$̲̅] ♦Sep 21, 2016 05:50 AM 0 245 Sep 21, 2016 05:50 AM
Last Post: ♦ [̲̅$̲̅(̲̅1000)̲̅$̲̅] ♦
[Shell] by ♦ [̲̅$̲̅(̲̅1000)̲̅$̲̅] ♦Sep 12, 2016 11:58 AM 2 222 Sep 12, 2016 11:58 AM
Last Post: ♦ [̲̅$̲̅(̲̅1000)̲̅$̲̅] ♦