1 # Copyright (C) 2010-2012 Alberto Gomez-Casado <a.gomezcasado@tnw.utwente.nl>
2 # W. Trevor King <wking@drexel.edu>
4 # This file is part of Hooke.
6 # Hooke is free software: you can redistribute it and/or modify it under the
7 # terms of the GNU Lesser General Public License as published by the Free
8 # Software Foundation, either version 3 of the License, or (at your option) any
11 # Hooke is distributed in the hope that it will be useful, but WITHOUT ANY
12 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 # A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with Hooke. If not, see <http://www.gnu.org/licenses/>.
21 Copies all .ibw files contained in a folder and its subfolders into a single folder. Useful for force maps.
24 python FMjoin.py origindir destdir
33 print 'You must at least specify origin and destination folders.'
38 if os.path.exists(origin):
39 if os.path.exists(dest):
40 if os.listdir(dest)!=[]:
41 print 'Destination folder is not empty! Use another folder.'
44 print 'Destination folder does not exist, will create it'
47 print 'You provided a wrong origin folder name, try again.'
49 origin=os.path.abspath(origin)
50 dest=os.path.abspath(dest)
52 for root, dirs, files in os.walk(origin):
53 for filename in files:
54 if filename.split('.')[1]!="ibw":
56 filepath=os.path.join(root,filename)
57 #to avoid overwriting, we collapse unique paths into filenames
58 rawdest=filepath.split(os.path.commonprefix([origin, filepath]))[1]
59 rawdest=rawdest.replace('/','') #for linux
60 rawdest=rawdest.replace('\\','') #for windows
61 destfile=os.path.join(dest,rawdest)
62 print 'Copying '+rawdest
63 shutil.copy(filepath,destfile)
67 if __name__ == '__main__':
68 sys.exit(main(*sys.argv))