5 Copies all .ibw files contained in a folder and its subfolders into a single folder. Useful for force maps.
8 python FMjoin.py origindir destdir
17 print 'You must at least specify origin and destination folders.'
22 if os.path.exists(origin):
23 if os.path.exists(dest):
24 if os.listdir(dest)!=[]:
25 print 'Destination folder is not empty! Use another folder.'
28 print 'Destination folder does not exist, will create it'
31 print 'You provided a wrong origin folder name, try again.'
33 origin=os.path.abspath(origin)
34 dest=os.path.abspath(dest)
36 for root, dirs, files in os.walk(origin):
37 for filename in files:
38 if filename.split('.')[1]!="ibw":
40 filepath=os.path.join(root,filename)
41 #to avoid overwriting, we collapse unique paths into filenames
42 rawdest=filepath.split(os.path.commonprefix([origin, filepath]))[1]
43 rawdest=rawdest.replace('/','') #for linux
44 rawdest=rawdest.replace('\\','') #for windows
45 destfile=os.path.join(dest,rawdest)
46 print 'Copying '+rawdest
47 shutil.copy(filepath,destfile)
51 if __name__ == '__main__':
52 sys.exit(main(*sys.argv))