From python-list Mon Aug 27 13:16:47 2007 From: JYOUNG79 () kc ! rr ! com Date: Mon, 27 Aug 2007 13:16:47 +0000 To: python-list Subject: RE:question Message-Id: X-MARC-Message: https://marc.info/?l=python-list&m=118822064918707 Hi MRAB, Thanks so much for taking the time to help me with this! I've learned a ton from the example you sent! I studied each part of your code so I could get a good understanding of how it worked. There was one question I had; on the regex line, you used "(\d+)$" and I was curious why you used the parenthesis around the '\d+'? After studying the 'listdir' a bit, I realized it only grabbed the files from the current directory I was in. I went online and with a little bit of searching I found 'walk'. I'm not sure if I'm using this correctly, but I found a way to use 'walk' to grab all the appropriate files in nested folders too (I attached the code below). I'm really impressed with the power of Python!! Again, thanks MRAB for the incredible help you've given me. I really appreciate it!! :-) Jay #!/usr/bin/python import os import re folder = "~/Desktop/logoFiles/" pathList = [] for root, dirs, files in os.walk(folder): for name in files: if name.upper().startswith("LOGO"): pathList.append(os.path.join(root, name)) dList = {} for x in pathList: parts = x.split("/") if parts[-2].isdigit(): # Make sure folder name is a number n = re.findall(r"(\d+)$", parts[-1]) # Grab number off file name if n: dList[int(n[0])] = "%s<::>LOGO%s\n" % (x, n[0]) keyList = dList.keys() keyList.sort() sortedList = "".join([dList[x] for x in keyList]) newFile = open("/Users/jyoung1/Desktop/LogoBook_Data/sortedData.txt", "w") newFile.write(sortedList) newFile.close() -- http://mail.python.org/mailman/listinfo/python-list