hi, i am creating a program to go through a directory structure recursively (including directories below it) and move all files that end in .msf to a directory above the current level.
the code i have so far is as follows: <code> #!/usr/bin/python #Author: Evan Carmi #Date: 20061101 #Purpose: To uncorrupt Mozilla Thunderbird mail index files. #Version: 2.04 top = 'f:\\test\\mail' import os, time, itertools #walk and find all files allfiles = [] for root, dirs, files in os.walk(top, topdown=False): for name in files: allfiles.append(os.path.join(root, name)) #remove all non .msf files index = [] for match in allfiles: if match.endswith('.msf'): index.append(match) print index #need to fix the problem with adding folders to thunderbird indexdest = [] indexdest = ['%s\\..\\..\\%s\\%s\\%s' % (x , time.strftime('%Y%m%d%H%M%S'), os.path.basename(os.path.normpath(x+'\\..')), os.path.basename(x)) for x in index] #\\.. to remove the ending and than basename to add it back on indexdest = [os.path.normpath(i) for i in indexdest] indexdest = [i.replace('Mail', 'backups-msf') for i in indexdest] for a, b in itertools.izip(index, indexdest): os.renames(a, b) </code> if the directory structure is: -test -Mail -Local Folders -mail.binarymanipulations.com and there are no additional directories inside of Local Folders than everything works and the script moves the .msf files to a directory on the same level as -Mail named backups-msf. the problem occurs when the directory structure: -test -Mail -Local Folders -mail.binarymanipulations.com has additional directories inside of Local Folders. This results in very odd behavior and the directory structure looks like: -test -Mail -Local Folders -mail.binarymanipulations.com -20061228005643 -Local Folders -mail.binarymanipulations.com after running the script. i hope that my problem is clear now, if you have any other information that would be helpful please tell me. I am testing this on a w2k machine with python 2.4 thanks, Evan -- http://mail.python.org/mailman/listinfo/python-list