Вопрос

I'm trying to copy my places.sqlite info to my desktop with python. It is stored at users\username\AppData\Roaming\Mozilla\Firefox\Profiles\rh425234.default\places.sqlite

However, what is want is to os.walk from \Profiles\ to \places.sqlite, and copy it to my desktop. This is what I have come up with:

dirs = '\\users\\username\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\'
cop_dir = '\\users\\Desktop\\

for r,d,f in os.walk(dirs):
    if 'places.sqlite' in f:
        shutil.copy2('places.sqlite', cop_dir)
        break

I think that shutil.copy2 needs a location to copy from and a location to copy to. The problem is that I don't know how to do it without adding \rh425234.default\ to the copy-from directory.

I've tried things like:

a = os.getcwd() + str(os.listdir(os.getcwd()))

to put into shutil.copy2(a, cop_dir) but that doesn't work. Any ideas?

Это было полезно?

Решение

Use os.path.join() to get the directory:

dirs = '\\users\\username\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\'
cop_dir = '\\users\\Desktop\\'

for r,d,f in os.walk(dirs):
    if 'places.sqlite' in f:
        shutil.copy2(os.path.join(r, 'places.sqlite'), cop_dir)
        break

Другие советы

for r,d,f in os.walk(dirs):
    if 'places.sqlite' in f:
        shutil.copy2(os.path.join(r, 'places.sqlite'), cop_dir)
        break
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top