source: flex_extract.git/python/UIOTools.py @ d69b677

ctbtodev
Last change on this file since d69b677 was d69b677, checked in by Anne Philipp <bscannephilipp@…>, 6 years ago

original ECMWFDATA v7.0.2 from flexpart.eu

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#!/usr/bin/env python                                                                                                                                                                     
2#                                                                                                                                                                                         
3# (C) Copyright 2014 UIO.
4#
5# This software is licensed under the terms of the Apache Licence Version 2.0
6# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
7#
8# Creation: October 2014 - Anne Fouilloux - University of Oslo
9#
10
11import os
12import glob
13
14class 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
19
20    def listFiles(self,pathname,pattern):
21        ''' list files (suffix previously given) within this directory. '''
22    # Get the absolute path of the pathname parameter
23        pathname = os.path.abspath(pathname)
24 
25    # Get a list of files in pathname
26        filesInCurDir0 = glob.glob(pathname+'/'+pattern)
27        filesInCurDir=[]
28        for f in filesInCurDir0:
29            filesInCurDir.append(f.split('/')[-1])
30        self.counter = 0
31        self.files = []
32    # Traverse through all files
33        for file in filesInCurDir:
34            curFile = os.path.join(pathname, file)
35 
36        # Check if it's a normal file or directory
37            if os.path.isfile(curFile):
38                # Get the file extension
39                fileNoExt,curFileExtension = os.path.splitext(curFile)
40                # Check if the file has an extension of typical video files
41                if curFileExtension in self.suffix:
42                    # We have got a file file! Increment the counter
43                    self.counter += 1
44                    # add this filename in the list
45                    self.files.append(curFile)
46                   
47            else:
48                # We got a directory, enter into it for further processing
49                self.listFiles(curFile)
50
51        return
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG