Module pl.dir
Useful functions for getting directory contents and matching them against wildcards
Functions
clonetree (path1, path2, file_fun, verbose) | clone a directory tree. |
copyfile (src, dest, flag) | copy a file. |
filter (files, pattern) | return a list of all files in a list of files which match the pattern. |
fnmatch (file, pattern) | does the filename match the shell pattern?. |
getdirectories (dir) | return a list of all subdirectories of the directory. |
getfiles (dir, mask) | return a list of all files in a directory which match the a shell pattern. |
makepath (p, path) | create a directory path. |
movefile (src, dest) | move a file. |
rmtree (fullpath, path) | remove a whole directory tree. |
Functions
- clonetree (path1, path2, file_fun, verbose)
-
clone a directory tree. Will always try to create a new directory structure if necessary.
Parameters:
-
path1
: the base path of the source tree -
path2
: the new base path for the destination -
file_fun
: an optional function to apply on all files -
verbose
:
Usage:
clonetree('.','../backup',copyfile)
Return value:
- if failed, false plus an error message. If completed the traverse, true, a list of failed directory creations and a list of failed file operations.
-
- copyfile (src, dest, flag)
-
copy a file.
Parameters:
-
src
: source file -
dest
: destination file -
flag
: true if you want to force the copy (default)
Return value:
- true if operation succeeded
-
- filter (files, pattern)
-
return a list of all files in a list of files which match the pattern. (cf. fnmatch.filter in Python, 11.8)
Parameters:
-
files
: A table containing file names -
pattern
: A shell pattern.
-
- fnmatch (file, pattern)
-
does the filename match the shell pattern?. (cf. fnmatch.fnmatch in Python, 11.8)
Parameters:
-
file
: A file name -
pattern
: A shell pattern
-
- getdirectories (dir)
-
return a list of all subdirectories of the directory.
Parameters:
-
dir
: A directory
-
- getfiles (dir, mask)
-
return a list of all files in a directory which match the a shell pattern.
Parameters:
-
dir
: A directory. If not given, all files in current directory are returned. -
mask
: A shell pattern. If not given, all files are returned.
-
- makepath (p, path)
-
create a directory path. This will create subdirectories as necessary!
Parameters:
-
p
: -
path
: A directory path
-
- movefile (src, dest)
-
move a file.
Parameters:
-
src
: source file -
dest
: destination file
Return value:
- true if operation succeeded
-
- rmtree (fullpath, path)
-
remove a whole directory tree.
Parameters:
-
fullpath
: -
path
: A directory path
-