-2

我想实现一个简单的脚本来在我的媒体电脑上做一些无聊的家务,但我不确定哪种脚本语言适合这项任务。

我想做的伪代码是:

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.

就是这样。尽管我可能想扩展它以随着时间的推移做更多的事情。对于用于此任务的最优雅的脚本工具有什么建议吗?

谢谢

4

2 回答 2

1

PowerShell 可以轻松完成您正在寻找的工作。查看Microsoft 的脚本中心。它有足够的示例和教程可以很快地解决这个问题。

于 2012-07-02T16:28:03.737 回答
1

我推荐 Python,因为你说你也想在你的 Mac 上使用它。使用shutilandos模块(查看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
于 2012-07-02T16:29:44.150 回答