[如何在Python中获取NautilusVFSFile对象的路径?或复制NautilusVFSFile以设置路径的方法

问题描述 投票:0回答:1

我正在尝试编写一个简单的Nautilus扩展。当我尝试添加副本文件时,会发生这种情况:

TypeError: cannot concatenate 'str' and 'NautilusVFSFile' objects

这是我的代码,我知道这不是真正的方法,但适用于与系统管理相关的学校科目

 def on_menu_item_clicked(self, item, files, folder):
    print [f.get_name() for f in files]
    print (folder)
    for file in files:
        print(file);
        os.system("cp '" + file + self.defaultPath + "/" + folder + "'")
python python-3.x gnome nautilus
1个回答
0
投票

对于将来某个时候使用Google搜索的人,此数据类型上有一个get_uri(),然后您就可以解析它并迅速获得路径

    def on_menu_item_clicked(self, item, files, folder):
    for file in files:
       srcPath = str(file.get_uri())
       srcPath = srcPath.split("file://")[1]
       os.system("cp -r '" + srcPath + "' '" + self.defaultPath + "/"+ folder + "'")
© www.soinside.com 2019 - 2024. All rights reserved.