利用nemo action实现New Folder Whith Selection

Ubuntu各种衍生版本
回复
头像
highwind
帖子: 1362
注册时间: 2008-09-05 23:31
系统: LinuxMint17

利用nemo action实现New Folder Whith Selection

#1

帖子 highwind » 2014-03-21 11:37

最近ee推荐了一个nautilus好用的功能:viewtopic.php?f=49&t=456746

正好最近学python,就动手造了一个轮子:
首先写个nemo-action:

代码: 全选

Exec=<NewFolderWithSelection.py %F>
Quote=double
然后在同一文件夹下写个py,记得要改成可执行文件哦:

代码: 全选

import os
import sys
from time import time,localtime,strftime
import shutil

DefPath=strftime("%Y-%m-%d_%H-%M-%S",localtime(time())) 
#这里借用了时间标签,防止万一有个同名文件夹,之后移动文件了,好再找回来,大家有什么更好的主意吗?
AllPath=[]
for i in sys.argv[1:]:
    AllPath.append(i)
CommonPath=os.path.commonprefix(AllPath)
isExists=os.path.exists(CommonPath)
if not isExists:
    pass
else:
    CommonPath=os.path.join(CommonPath,DefPath)

os.makedirs(CommonPath)
for i in sys.argv[1:]:
    shutil.move(i,CommonPath)
回复