Statistics
| Branch: | Revision:

root / globecomm / utility.py @ fac6e5a4

History | View | Annotate | Download (669 Bytes)

1
import os
2

    
3
def get_int(name):
4
    """Helper function of all_files_for_network()
5
    """
6
    basename = name.partition('.')[0]
7
    # print basename
8
    alpha, num = basename.split('_')
9
    return int(num)
10

    
11

    
12
def all_files_for_network(network_name, dir):
13
    """Returns the all the files started with the <network_name>
14
    in the sorted order in the <dir> directory
15

16
    Sample output: [FFGraz_1.edges, FFGraz_2.edges, ...., FFGraz_10.edges, ...]
17
    """
18
    files = []
19
    for file in os.listdir(dir):
20
        prefix = file.split('_')[0]
21
        if prefix == network_name:
22
            files.append(os.path.join(dir, file))
23

    
24
    files.sort(key=get_int)
25

    
26
    return files