2012-07-02 36 views
-2

我想實現一個簡單的腳本在我的媒體pc上做一些無聊的家務,但我不確定哪種腳本語言會適合這項任務。你會爲這項任務推薦什麼腳本語言?

僞什麼我想要做的是:

1) Scan a directory for sub directories matching a name like: 

"Foo 1x01 bar" 
"Foo 1x02 bar" 
or 
"Foo s01e01 bar" 
"Foo s01e02 bar" 



2) Then for each matching sub directory: 
    - Make a directory "Foo" if it doesn't already exist. 
    - Copy the largest file under the matching sub directory into "Foo". 
    - Delete the matched sub directory and anything left in it. 

就是這樣。儘管我可能希望將其擴展爲隨着時間的推移做更多。任何關於最優雅的腳本工具用於此任務的建議?

謝謝

+0

使用哪種操作系統? – CodeZombie

+0

清理一些下載呃? – TheZ

+0

是的:) - 這是在Windows 7上,但會很高興能夠重用我的mac也 – user1496565

回答

1

我會推薦Python,因爲你聲明你也想在你的Mac上使用它。 使用shutilos模塊(查看os.walk),它應該很容易。 這是一個從top變量中的文件夾開始獲取所有文件大小的示例。

import os 
from os.path import join, getsize 
for root, dirs, files in os.walk('python/Lib/email'): 
    print root, "consumes", 
    print sum(getsize(join(root, name)) for name in files), 
    print "bytes in", len(files), "non-directory files" 
    if 'CVS' in dirs: 
     dirs.remove('CVS') # don't visit CVS directories 
+0

這是一個很好的起點。謝謝! – user1496565

1

PowerShell可以輕鬆地做你正在尋找的東西。檢出Microsoft's Script Center。它有足夠的例子和tutuorials很快爆炸這個。