Hack Forums
[Python] Clean your desktop! - 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] Clean your desktop! (/showthread.php?tid=5743792)



Clean your desktop! - inv3ctus - Oct 27, 2017

Code
import os

desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
clean_folder = 'Shit'

def clean(from_dir, spec_dir):
   for file in os.listdir(from_dir):
       if not '.lnk' in file and file != clean_folder:
           try:
               os.rename(from_dir + '\\' + file, spec_dir + '\\' + file)
           except:
               pass

def fu_clean():
   curr_dir = os.getcwd()
   os.chdir(desktop)
   clean(desktop, desktop + '\\' + clean_folder)
   os.chdir(curr_dir)

if not clean_folder in os.listdir(desktop):
   os.mkdir(desktop + '\\' + clean_folder)

fu_clean()
*Github Link*

This code makes a folder on your desktop with all the files and folder that are currently on your desktop, except for the shortcuts!
Perfect for keeping your computer organized!


RE: Clean your desktop! - vaxton - Oct 27, 2017

i just tried it out and it worked!
thank you so much for this share :)


RE: Clean your desktop! - adnankatman - Oct 27, 2017

Awesome, saved to my python_utils folder!


RE: Clean your desktop! - vorticalbox - Oct 28, 2017

This will only work on windows, for us Linux folk the desktop folder is ~/Desktop


RE: Clean your desktop! - inv3ctus - Oct 28, 2017

(Oct 28, 2017 02:27 AM)vorticalbox Wrote:  This will only work on windows, for us Linux folk the desktop folder is ~/Desktop

Oh yeah, should have said that! But feel free to edit the code!


RE: Clean your desktop! - vorticalbox - Oct 28, 2017

(Oct 28, 2017 02:56 AM)₱yAssassin Wrote:  Oh yeah, should have said that! But feel free to edit the code!

totally would but currently doing a coding challenge for a job in node.js. only started learning it last week and man this shit is confusing, EVERYTHING is async and you have to be so carful when processing stuff lol