0

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?

  • 1
    Have you tried `shutil.copy('c:/users/username/AppData/Roaming/Mozilla/Firefox/Profiles/places.sqlite', 'c:/users/username/desktop/')`? – Blender Apr 30 '13 at 23:39
  • In between /Profiles and /places.sqlite, there is a folder that is assigned a random name, so that doesn't work. I'm trying to do this with the assumption that I won't be able to know the name of that folder. – user2256199 Apr 30 '13 at 23:46
  • You could use the `glob` module and use a wildcard: `/foo/*/bar` – Blender Apr 30 '13 at 23:47

2 Answers2

0
for r,d,f in os.walk(dirs):
    if 'places.sqlite' in f:
        shutil.copy2(os.path.join(r, 'places.sqlite'), cop_dir)
        break
PasteBT
  • 2,128
  • 16
  • 17
0

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
tdelaney
  • 73,364
  • 6
  • 83
  • 116
  • What exactly does the 'r' do in (os.path.join(r, 'places.sqlite') – user2256199 May 01 '13 at 00:10
  • @user2256199 the r is just the variable you used for the first os.walk return value and holds the current directory where the files (your f variable) are located. Os.path.jion glues them together. – tdelaney May 01 '13 at 03:58