桌面盒子Deskbox - 快速清潔我的 Windows 桌面

在家中使用 Mac 時我可以使用 Desktoday 將我桌面上的檔案通通清除乾淨,不過在 Windows 上卻缺少了這套好的軟體,因此我寫了一個批次檔案叫做「桌面盒子 Deskbox」,對於沒擺捷徑在桌面上的我來說能夠快速做到收納檔案的效果。

@echo off
color 02
Rem version 0.4 增加我的影片資料夾
Rem 取得目前的時間作為當天資料夾名稱
For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set date=%%a年%%b月%%c日)
set WhereIsBatch=%CD%

Rem 取得桌面路徑
reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop | find "Desktop" > deskbox_pin_%date%.txt
for /F "tokens=2 delims=\" %%a in (deskbox_pin_%date%.txt) do set "desktop=%userprofile%\%%a"
del deskbox_pin_%date%.txt
echo 資料歸檔中

Rem 設定收納桌面檔案的資料名稱
set LovelyName=Dbox

Rem 設定來源資料夾路徑,預設為桌面
set Source=%desktop%

Rem 設定目標資料夾路徑

set Target=%WhereIsBatch%\%date%


IF NOT EXIST %Target% mkdir %Target%



Rem 建立分類資料夾
for /F %%i in ('dir /b "%Source%\*.*"') do (
   mkdir "%Target%\桌面"
)

for /F %%i in ('dir /b "%userprofile%\My Documents\Downloads\*.*"') do (
   mkdir "%Target%\下載"
)

for /F %%i in ('dir /b "%userprofile%\Downloads\*.*"') do (
   mkdir "%Target%\下載"
)

for /F %%i in ('dir /b "%userprofile%\My Documents\Google Talk Received Files\*.*"') do (
   mkdir "%Target%\Google Talk Received Files"
)

for /F %%i in ('dir /b "%userprofile%\Videos\*.*"') do (
   mkdir "%Target%\Google Talk Received Files"
)




FOR    %%i IN ("%Source%\*") DO           MOVE /-Y "%%i" "%Target%\桌面\%%~nxi"
FOR /D %%i IN ("%Source%\*") DO ROBOCOPY /MOVE /E "%%i" "%Target%\桌面\%%~nxi"

REM Windows XP Download 資料夾
FOR    %%i IN ("%userprofile%\My Documents\Downloads\*") DO           MOVE /-Y  "%%i" "%Target%\下載\%%~nxi"
FOR /D %%i IN ("%userprofile%\My Documents\Downloads\*") DO ROBOCOPY /MOVE /E "%%i" "%Target%\下載\%%~nxi"

REM Windows 7 Download 資料夾
FOR    %%i IN ("%userprofile%\Downloads\*") DO           MOVE /-Y  "%%i" "%Target%\下載\%%~nxi"
FOR /D %%i IN ("%userprofile%\Downloads\*") DO ROBOCOPY /MOVE /E "%%i" "%Target%\下載\%%~nxi"


REM Google Talk 資料夾
FOR    %%i IN ("%userprofile%\My Documents\Google Talk Received Files\*") DO           MOVE /-Y  "%%i" "%Target%\Google Talk Received Files\%%~nxi"
FOR /D %%i IN ("%userprofile%\My Documents\Google Talk Received Files\*") DO ROBOCOPY /MOVE /E "%%i" "%Target%\Google Talk Received Files\%%~nxi"

REM Videos 資料夾
FOR    %%i IN ("%userprofile%\Videos\*") DO           MOVE /-Y  "%%i" "%Target%\我的影片\%%~nxi"
FOR /D %%i IN ("%userprofile%\Videos\*") DO ROBOCOPY /MOVE /E "%%i" "%Target%\我的影片\%%~nxi"



如果你是在 Windows XP 上使用,缺乏了 robocopy 的指令,因此沒辦法直接使用,需要先安裝微軟的這款軟體:

  •  Windows Server 2003 Resource Kit Tools [下載]

別把 Deskbox.bat 放在桌面上,不然他一天到晚就會跟著被封存起來,扔在 D 槽也是個不錯的選擇。Windows XP 可以使用快速啟動列來使用;Windows 7 可以使用 TaskBarPinner 將 batch 檔案釘在工作列上。


缺點:移除桌面檔案的最大問題就是無法避免的連「桌面」資料夾都會跟著被移走,一旦被移走就必須要從工作管理員內重新啟動 explorer.exe,因此有網友 WhoIsRich 想出來使用 move 跟 robocopy 兩個指令分別移走檔案跟資料夾,但缺點就是無法排除哪些檔案不要被複製,例如:捷徑。

感謝:你知道 Windows XP 的桌面的資料夾名稱就叫做「桌面」,是個中文的名稱;而 Windows 7 的桌面則是「desktop」,這是為了避免在地化之後就連最基本的「桌面資料夾」的名稱會因為各個語言版本而有數十種路徑。為了取得桌面路徑,網友 Inndy Lin 寫了從登錄檔取得桌面路徑的方式,應該在 XP 跟 Windows 7 都可以運作正常。

Ref.
  1. windows - Robocopy: How to move the content of a directory but KEEP the directory - Server Fault - http://goo.gl/HMhhq
  2. I's制空域: Batch取得桌面路徑 Get Desktop Path In Batch - http://goo.gl/5bcBj

小泉

喜愛用文字說明自己眼中所見的一切

張貼留言

較新的 較舊

نموذج الاتصال