![]() |
|
[Python] Delete Files Program - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Delete Files Program (/showthread.php?tid=5049350) |
Delete Files Program - Baba Yaga - Nov 7, 2015 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:
Here is the code: Code import time* - SavageBoys - Nov 7, 2015 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) * - Baba Yaga - Nov 7, 2015 (Nov 7, 2015 02:17 PM)Evоlutiоn Wrote: del works in windows and rm works on linux, unix, mac. 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 🤝 * - SavageBoys - Nov 7, 2015 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) * - WojeT - Nov 7, 2015 Don't use os.system it just makes it more complicated. See this post on SO http://stackoverflow.com/a/6996628 |