Changeset 507d47f in flex_extract.git
- Timestamp:
- Feb 5, 2018, 2:50:48 PM (6 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 9ac56ea
- Parents:
- a4b6cef
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/UIOTools.py
rd69b677 r507d47f 1 #!/usr/bin/env python 2 # 1 #!/usr/bin/env python 2 # 3 3 # (C) Copyright 2014 UIO. 4 4 # … … 9 9 # 10 10 11 12 #************************************************************************ 13 # TODO AP 14 # 15 # - File name und Klassenname gleichsetzen? 16 # - checken welche regelmässigen methoden auf diese Files noch angewendet werden 17 # und dann hier implementieren 18 # - löschen? 19 #************************************************************************ 20 11 21 import os 12 22 import glob 13 23 14 24 class UIOFiles: 15 'class to manipulate files' 16 def __init__(self,suffix): 17 # type of files to manipulate such as ['.grib', 'grb', 'grib1', 'grib2', 'grb1','grb2'] 18 self.suffix=suffix 25 ''' 26 Class to manipulate files. At initialisation it has the attribute 27 suffix which stores a list of suffixes of the files associated 28 with the instance of the class. 29 ''' 19 30 20 def listFiles(self,pathname,pattern): 21 ''' list files (suffix previously given) within this directory. ''' 22 # Get the absolute path of the pathname parameter 31 def __init__(self, suffix): 32 ''' 33 @Description: 34 Assignes the suffixes of the files which should be 35 associated with the instance of the class. 36 37 @Input: 38 self: instance of UIOFiles 39 Description see class documentation. 40 41 suffix: list of strings 42 Types of files to manipulate such as 43 ['.grib', 'grb', 'grib1', 'grib2', 'grb1','grb2'] 44 45 @Return: 46 <nothing> 47 ''' 48 self.suffix = suffix 49 return 50 51 def listFiles(self, pathname, pattern): 52 ''' 53 @Description: 54 Lists all files in the directory with the matching 55 regular expression pattern. The suffixes are already stored 56 in a list attribute "suffix". 57 58 @Input: 59 self: instance of UIOFiles 60 Description see class documentation. 61 62 pathname: string 63 Directory where to list the files. 64 65 pattern: string 66 Regular expression pattern. For example: 67 '*OG_acc_SL*.'+c.ppid+'.*' 68 69 @Return: 70 <nothing> 71 ''' 72 # Get the absolute path of the pathname parameter 23 73 pathname = os.path.abspath(pathname) 24 25 # Get a list of files in pathname26 filesInCurDir0 = glob.glob(pathname +'/'+pattern)27 filesInCurDir =[]74 75 # Get a list of files in pathname 76 filesInCurDir0 = glob.glob(pathname + '/' + pattern) 77 filesInCurDir = [] 28 78 for f in filesInCurDir0: 29 79 filesInCurDir.append(f.split('/')[-1]) 30 80 self.counter = 0 31 81 self.files = [] 32 # Traverse through all files82 # Traverse through all files 33 83 for file in filesInCurDir: 34 84 curFile = os.path.join(pathname, file) 35 36 # Check if it's a normal file or directory85 86 # Check if it's a normal file or directory 37 87 if os.path.isfile(curFile): 38 88 # Get the file extension 39 fileNoExt, curFileExtension = os.path.splitext(curFile)89 fileNoExt, curFileExtension = os.path.splitext(curFile) 40 90 # Check if the file has an extension of typical video files 41 91 if curFileExtension in self.suffix: … … 44 94 # add this filename in the list 45 95 self.files.append(curFile) 46 47 96 else: 48 97 # We got a directory, enter into it for further processing
Note: See TracChangeset
for help on using the changeset viewer.