Jakub Karp
Jakub Karp

Reputation: 21

How to get path of NautilusVFSFile object in Python? Or a way to copy NautilusVFSFile to set path

I'm trying to write a simple Nautilus extension. When I'm trying to add copy a file this happens:

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

That's my code, I know It's not really the way to do It, but It's for School Subject connected with System Administration

 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 + "'")

Upvotes: 1

Views: 169

Answers (1)

Jakub Karp
Jakub Karp

Reputation: 21

For anyone Googling it sometime in the future, there is a get_uri() on this data type, and then you can parse It and boom you got your path

    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 + "'")

Upvotes: 1

Related Questions