author | Tero Marttila <tero.marttila@aalto.fi> |
Mon, 02 Mar 2015 19:58:35 +0200 | |
changeset 700 | 88b0d3df1ad7 |
parent 684 | fbac5a08c9d3 |
permissions | -rw-r--r-- |
627 | 1 |
### FS utils |
2 |
||
3 |
function _list { |
|
4 |
local glob="$1" |
|
5 |
local test="$2" |
|
6 |
local prefix="$3" |
|
7 |
||
8 |
for file in $glob; do |
|
9 |
[ $test "$file" ] || continue |
|
10 |
[ -n "$prefix" ] && file="${file#$prefix}" |
|
11 |
||
12 |
echo -n "$file " |
|
13 |
done |
|
14 |
} |
|
15 |
||
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
16 |
## List names of all things in dir |
627 | 17 |
function list { |
18 |
_list "$1/*" '-e' ${2:-$1/} |
|
19 |
} |
|
20 |
||
21 |
## List names of files in dir: |
|
22 |
# |
|
23 |
# list_files $dir |
|
24 |
# |
|
25 |
function list_files { |
|
26 |
_list "$1/*" '-f' ${2:-$1/} |
|
27 |
} |
|
28 |
||
29 |
## List names of dirs in dir: |
|
30 |
function list_dirs { |
|
31 |
_list "$1/*" '-d' ${2:-$1/} |
|
32 |
} |
|
33 |
||
684
fbac5a08c9d3
lib/pvl: pvl/list: fix list_tree to include directory itself
Tero Marttila <tero.marttila@aalto.fi>
parents:
628
diff
changeset
|
34 |
## Expand a file or directory path to any files/directorys within that tree |
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
35 |
function list_tree { |
684
fbac5a08c9d3
lib/pvl: pvl/list: fix list_tree to include directory itself
Tero Marttila <tero.marttila@aalto.fi>
parents:
628
diff
changeset
|
36 |
_list "$1 $1/**" '-e' '' |
627 | 37 |
} |