source: flexpart.git/preproc/python/UIOTools.py @ ec9d8da

10.4.1_peseiFPv9.3.1FPv9.3.1b_testingFPv9.3.2GFS_025bugfixes+enhancementsdevfp9.3.1-20161214-nc4grib2nc4_repairrelease-10release-10.4.1scaling-bugunivie
Last change on this file since ec9d8da was 5763793, checked in by Anne Fouilloux <annefou@…>, 9 years ago

Add pre-processing programs and examples. This is still under development!

  • Property mode set to 100644
File size: 1.9 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
12
13class UIOFiles:
14    'class to manipulate files'
15    def __init__(self,suffix):
16# type of files to manipulate such as ['.grib', 'grb', 'grib1', 'grib2', 'grb1','grb2']
17        self.suffix=suffix
18
19    def listFiles(self,pathname):
20        ''' list files (suffix previously given) within this directory. '''
21    # Get the absolute path of the pathname parameter
22        pathname = os.path.abspath(pathname)
23 
24    # Get a list of files in pathname
25        filesInCurDir = os.listdir(pathname)
26        self.counter = 0
27        self.files = []
28    # Traverse through all files
29        for file in filesInCurDir:
30            curFile = os.path.join(pathname, file)
31 
32        # Check if it's a normal file or directory
33            if os.path.isfile(curFile):
34                # Get the file extension
35                fileNoExt,curFileExtension = os.path.splitext(curFile)
36                # Check if the file has an extension of typical video files
37                if curFileExtension in self.suffix:
38                    # We have got a file file! Increment the counter
39                    self.counter += 1
40                    # add this filename in the list
41                    self.files.append(curFile)
42                   
43            else:
44                # We got a directory, enter into it for further processing
45                self.listFiles(curFile)
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG