Monthly Archives: September 2011
Protected: CSE 590: Homework 1
Posted in Homework Submission, Uncategorized Enter your password to view comments.
Export Picasa 2 Albums to Folders
I recently needed to move some Picasa 2 albums from an old computer to a new one given only the old files and album files. I’d about had it with albums, so I wrote a Python script to convert .pal (Picasa albums) into regular folders.
It chokes on unicode, but dumps errors to a file for you to resolve them – just run this in a directory with your .pil files and it will create subfolders for each album and copy the pictures into them, as well. Use at your own risk.
#!/usr/bin/python2 from xml.dom.minidom import parse import os.path import shutil PICTURESPATH = "C:\\Users\\User\\Documents\\oldcomp\\My Pictures" ERRORS = open('errors.txt','w') def populateFolder(albumName): global PICTURESPATH global ERRORS doc = parse(albumName) title = [x for x in doc.getElementsByTagName("property") if x.getAttribute("name")=="name"] title = title.getAttribute("value") files = map(lambda x: x.childNodes.nodeValue, doc.getElementsByTagName("filename")) translated = map(lambda x: os.path.expandvars(x).replace("$My Pictures",PICTURESPATH), files) try: os.mkdir(title) except: ERRORS.write("Cant make directory " + title) for f in translated: try: shutil.copy(f, title + "/") except: ERRORS.write("Error in album %s: %s\n" % (title, f)) def main(): fileList = filter(lambda x: ".pal" in x, os.listdir(".")) for cFile in fileList: populateFolder(cFile) if __name__=="__main__": main()
Posted in Code Leave a comment