blob: 0abfae46e0b3d65ecfa68c6f29cbe7e9c8860122 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# Copyright 2013 Aditya Naik
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
"""A tiny module for creating lists of abspath of files in a directory.
Also creates lists by isolating the files of the required extension."""
import re
import os
import sys
def listpaths(path):
"""Get a list of all files"""
global filedir
filedir=[]
filepath=os.listdir(path)
for filename in filepath:
filedir.append(os.path.join(os.path.abspath(path),filename))
return filedir
def listext(path,ext):
"""This function will list all files in the specified path with the given extension"""
global filedir
filedir=[]
filepath=os.listdir(path)
for filename in filepath:
filedir.append(os.path.join(os.path.abspath(path),filename))
i=0
while i <len(filedir):
if filedir[i][-len(ext):]!=ext: filedir.pop(i)
else: i=i+1
return filedir
|