python 好玩的 桌面清理 管家

2021-09-20 06:08:10 字數 4183 閱讀 1908

博主本人用電腦時一直有乙個不好的習慣,就是喜歡把檔案存在放在桌面上,結果沒過多久桌面就全是各種word,excel檔案了,顯得桌面十分的亂,但是又改不掉這個習慣,真是讓人腦袋疼!(。>︿

電腦桌面就像這樣

使用python編寫乙個電腦桌面清理"管家",自動分析桌面檔案字尾名。

將桌面上常規的辦公檔案儲存在e盤下的work資料夾下。

將剩餘字尾名的檔案儲存在e盤下的other資料夾下。

【需要提前在e盤下建立work和other這兩個資料夾哦!( •̀ ω •́ )✧】

1.定於乙個用於獲得指定目錄下的檔案列表的函式

def get_file(self,path=''):

"""返回指定目錄下的檔案列表

"""return os.listdir(path)

2.定義乙個用於檔案分類的函式

def classification(self,file_list):

"""檢測檔案字尾進行分類

"""for file in file_list:

if ('.' in file):

#檢測是否是檔案型別

file_name,file_type = file[-5:].split('.')

#分割檔名和檔案型別

if file_type in self.sys_type:

#檢測是否為系統型別,如果是則跳過

continue

elif file_type in self.work_type:

#檢測是否為辦公檔案型別,如果是則加入work_list

else:

#檢測是否為其他檔案型別,如果是則加入other_list

3.定義乙個用於補齊檔案路徑的函式

def move(self):

"""迴圈提取檔案,然後呼叫移動函式

"""if len(self.work_list) > 0:

for file in self.work_list:

print ("正在移動{}".format(file))

src_file = self.desktop_path+'\\'+file

des_file = self.work_path+'\\'+file

self.file_move(src_file,des_file)

self.work_list.remove(file)

elif len(self.other_list) > 0:

for file in self.other_list:

print ('正在移動{}'.format())

src_file = self.desktop_path+'\\'+file

des_file = self.other_path+'\\'+file

self.file_move(src_file,des_file)

self.other_list.remove(file)

else:

pass

4.定義乙個用於移動檔案的函式

def file_move(self,src_file,des_file):

"""移動檔案

"""try:

shutil.move(src_file,des_file)

except:

pass

5.定義乙個主函式用於呼叫上述函式

def main(self):

while true:

time.sleep(10)

file_list = self.get_file(self.desktop_path)

self.classification(file_list)

# -*- coding:utf-8 -*-

#creators: 貓先生的早茶

import os

import shutil

import time

class zeam():

def __init__(self):

self.desktop_path = os.popen(r'echo %userprofile%\desktop').read().rstrip('\n')

self.work_path = r'e:\\work'

self.other_path = r'e:\\other'

self.work_type = ['xlx','xlsx','ppt','pptx','doc','docx','txt']

self.sys_type = ['ini','lnk']

self.work_list =

self.other_list =

def get_file(self,path=''):

"""返回指定目錄下的檔案列表

"""return os.listdir(path)

def classification(self,file_list):

"""檢測檔案字尾進行分類

"""for file in file_list:

if ('.' in file):

#檢測是否是檔案型別

file_name,file_type = file[-5:].split('.')

#分割檔名和檔案型別

if file_type in self.sys_type:

#檢測是否為系統型別,如果是則跳過

continue

elif file_type in self.work_type:

#檢測是否為辦公檔案型別,如果是則加入work_list

else:

#檢測是否為其他檔案型別,如果是則加入other_list

self.move()

def file_move(self,src_file,des_file):

"""移動檔案

"""try:

shutil.move(src_file,des_file)

except:

pass

def move(self):

"""迴圈提取檔案,然後呼叫移動函式

"""if len(self.work_list) > 0:

for file in self.work_list:

print ("正在移動{}".format(file))

src_file = self.desktop_path+'\\'+file

des_file = self.work_path+'\\'+file

self.file_move(src_file,des_file)

self.work_list.remove(file)

elif len(self.other_list) > 0:

for file in self.other_list:

print ('正在移動{}'.format())

src_file = self.desktop_path+'\\'+file

des_file = self.other_path+'\\'+file

self.file_move(src_file,des_file)

self.other_list.remove(file)

else:

pass

def main(self):

while true:

time.sleep(10)

file_list = self.get_file(self.desktop_path)

self.classification(file_list)

zeam = zeam()

zeam.main()

print ("桌面清理管家正在執行。。。")

win10設定開機執行

win7設定開機執行

執行後的效果圖如下:

提取碼:rr0o

用hta做的好玩的小程式 固定在桌面

大家好,開始了啊 先在桌面上建個文本文擋將下面的程式複製進去 複製 如下 測試 o o.哈哈 程式設計客棧nter 月亮代表我的心 愛的通知 老五,不要問我愛你有多深 我愛你有幾分 愛的路上只有我和你 月亮代表我的心!儲存將字尾改為hta 好了大家可以看看 不錯吧裡邊的字可以隨便改 12秒自動關閉,...

Python一些好玩的方法

開頭嘮叨兩句 有啥好玩的方法可以告訴我,積累一些小 斷 現在有12345五個東西,求分成2,3,4,5組的全排列總和,且每組每個方法不能重複。320種 for i in range 2,6 for j in itertools.permutations 12345 i print int x for...

Python 一些好玩的函式

一 匿名函式 什麼匿名是函式 不需要使用def函式名的函式或者子程式 函式語法 lambda 引數 表示式 函式特點 1 lambda只是乙個表示式,省去定義函式過程,讓 更精簡 2 lambda 在表示式中封裝的邏輯有限 3 不能訪問自己引數序列外或者全域性命名空間的引數 舉例 二 內建map 函...