我想实现一个简单的脚本来在我的媒体电脑上做一些无聊的内务管理,但我不确定哪种脚本语言会适合这项任务。
我想做的伪代码是:
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 :(得分:1)
PowerShell可以轻松完成您所需的工作。查看Microsoft's Script Center。它有足够的例子和tutuorial很快就能解决这个问题。
答案 1 :(得分:1)
我推荐使用Python,因为你声明你也想在Mac上使用它。
使用shutil
和os
模块(查看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