eric7.SystemUtilities.FileSystemUtilities
Module implementing file system related utility functions.
Global Attributes
Classes
Functions
absolutePath |
Public method to convert a path relative to a start path to an absolute path. |
absoluteUniversalPath |
Public method to convert a path relative to a start path with universal separators to an absolute path. |
compactPath |
Function to return a compacted path fitting inside the given width. |
direntries |
Function returning a list of all files and directories. |
findVolume |
Function to find the directory belonging to a given volume name. |
fromNativeSeparators |
Function returning a path, that is using "/" separator characters. |
getDirs |
Function returning a list of all directories below path. |
getExecutablePath |
Function to build the full path of an executable file from the environment. |
getExecutablePaths |
Function to build all full path of an executable file from the environment. |
getUserMounts |
Function to determine all available user mounts. |
getVolumeName |
Local function to determine the volume of a disk or device. |
getWindowsExecutablePath |
Function to build the full path of an executable file from the environment on Windows platforms. |
isDrive |
Function to check, if a path is a Windows drive. |
isExecutable |
Function to check, if a file is executable. |
isinpath |
Function to check for an executable file. |
joinext |
Function to join a file extension to a path. |
normabsjoinpath |
Function returning a normalized, absolute path of the joined parts passed into it. |
normcaseabspath |
Function returning an absolute path, that is normalized with respect to its case and references. |
normcasepath |
Function returning a path, that is normalized with respect to its case and references. |
normjoinpath |
Function returning a normalized path of the joined parts passed into it. |
relativeUniversalPath |
Function to convert a file path to a path relative to a start path with universal separators. |
samefilepath |
Function to compare two paths. |
samepath |
Function to compare two paths. |
splitPath |
Function to split a pathname into a directory part and a file part. |
startswithPath |
Function to check, if a path starts with a given start path. |
toNativeSeparators |
Function returning a path, that is using native separator characters. |
absolutePath
absolutePath(path, start)
Public method to convert a path relative to a start path to an
absolute path.
- path
-
file or directory name to convert (string)
- start
-
start path (string)
- Return:
-
absolute path (string)
absoluteUniversalPath
absoluteUniversalPath(path, start)
Public method to convert a path relative to a start path with
universal separators to an absolute path.
- path
-
file or directory name to convert (string)
- start
-
start path (string)
- Return:
-
absolute path with native separators (string)
compactPath
compactPath(path, width, measure=len)
Function to return a compacted path fitting inside the given width.
- path
-
path to be compacted (string)
- width
-
width for the compacted path (integer)
- measure
-
reference to a function used to measure the length of the
string
- Return:
-
compacted path (string)
direntries
direntries(path, filesonly=False, pattern=None, followsymlinks=True, checkStop=None, ignore=None, )
Function returning a list of all files and directories.
- path (str)
-
root of the tree to check
- filesonly (bool)
-
flag indicating that only files are wanted
- pattern (str or list of str)
-
a filename pattern or list of filename patterns to check
against
- followsymlinks (bool)
-
flag indicating whether symbolic links
should be followed
- checkStop (function)
-
function to be called to check for a stop
- ignore (list of str)
-
list of entries to be ignored
- Return:
-
list of all files and directories in the tree rooted
at path. The names are expanded to start with path.
- Return Type:
-
list of strs
findVolume
findVolume(volumeName, findAll=False)
Function to find the directory belonging to a given volume name.
- volumeName (str)
-
name of the volume to search for
- findAll (bool (optional))
-
flag indicating to get the directories for all volumes
starting with the given name (defaults to False)
- Return:
-
directory path or list of directory paths for the given volume
name
- Return Type:
-
str or list of str
fromNativeSeparators
fromNativeSeparators(path)
Function returning a path, that is using "/" separator characters.
- path (str)
-
path to be converted
- Return:
-
path with converted separator characters
- Return Type:
-
str
getDirs
getDirs(path, excludeDirs)
Function returning a list of all directories below path.
- path
-
root of the tree to check
- excludeDirs
-
basename of directories to ignore
- Return:
-
list of all directories found
getExecutablePath
getExecutablePath(file)
Function to build the full path of an executable file from the environment.
- file
-
filename of the executable to check (string)
- Return:
-
full executable name, if the executable file is accessible
via the searchpath defined by the PATH environment variable, or an
empty string otherwise.
getExecutablePaths
getExecutablePaths(file)
Function to build all full path of an executable file from the environment.
- file
-
filename of the executable (string)
- Return:
-
list of full executable names (list of strings), if the executable
file is accessible via the searchpath defined by the PATH environment
variable, or an empty list otherwise.
getUserMounts
getUserMounts()
Function to determine all available user mounts.
Note: On Windows platforms all available drives are returned.
- Return:
-
list of user mounts or drives
- Return Type:
-
list of str
getVolumeName
getVolumeName(diskName)
Local function to determine the volume of a disk or device.
Each disk or external device connected to windows has an
attribute called "volume name". This function returns the
volume name for the given disk/device.
Code from http://stackoverflow.com/a/12056414
getWindowsExecutablePath
getWindowsExecutablePath(file)
Function to build the full path of an executable file from the environment
on Windows platforms.
First an executable with the extension .exe is searched for, thereafter
such with the extensions .cmd or .bat and finally the given file name as
is. The first match is returned.
- file
-
filename of the executable to check (string)
- Return:
-
full executable name, if the executable file is accessible
via the searchpath defined by the PATH environment variable, or an
empty string otherwise.
isDrive
isDrive(path)
Function to check, if a path is a Windows drive.
- path (str)
-
path name to be checked
- Return:
-
flag indicating a Windows drive
- Return Type:
-
bool
isExecutable
isExecutable(exe)
Function to check, if a file is executable.
- exe
-
filename of the executable to check (string)
- Return:
-
flag indicating executable status (boolean)
isinpath
isinpath(file)
Function to check for an executable file.
- file
-
filename of the executable to check (string)
- Return:
-
flag to indicate, if the executable file is accessible
via the searchpath defined by the PATH environment variable.
joinext
joinext(prefix, ext)
Function to join a file extension to a path.
The leading "." of ext is replaced by a platform specific extension
separator if necessary.
- prefix
-
the basepart of the filename (string)
- ext
-
the extension part (string)
- Return:
-
the complete filename (string)
normabsjoinpath
normabsjoinpath(a, *p)
Function returning a normalized, absolute path of the joined parts passed
into it.
- a
-
first path to be joined (string)
- p
-
variable number of path parts to be joind (string)
- Return:
-
absolute, normalized path (string)
normcaseabspath
normcaseabspath(path)
Function returning an absolute path, that is normalized with respect to
its case and references.
- path
-
file path (string)
- Return:
-
absolute, normalized path (string)
normcasepath
normcasepath(path)
Function returning a path, that is normalized with respect to its case
and references.
- path
-
file path (string)
- Return:
-
case normalized path (string)
normjoinpath
normjoinpath(a, *p)
Function returning a normalized path of the joined parts passed into it.
- a
-
first path to be joined (string)
- p
-
variable number of path parts to be joined (string)
- Return:
-
normalized path (string)
relativeUniversalPath
relativeUniversalPath(path, start)
Function to convert a file path to a path relative to a start path
with universal separators.
- path
-
file or directory name to convert (string)
- start
-
start path (string)
- Return:
-
relative path or unchanged path, if path does not start with
the start path with universal separators (string)
samefilepath
samefilepath(f1, f2)
Function to compare two paths. Strips the filename.
- f1
-
first filepath for the compare (string)
- f2
-
second filepath for the compare (string)
- Return:
-
flag indicating whether the two paths represent the
same path on disk.
samepath
samepath(f1, f2)
Function to compare two paths.
- f1
-
first path for the compare (string)
- f2
-
second path for the compare (string)
- Return:
-
flag indicating whether the two paths represent the
same path on disk.
splitPath
splitPath(name)
Function to split a pathname into a directory part and a file part.
- name
-
path name (string)
- Return:
-
a tuple of 2 strings (dirname, filename).
startswithPath
startswithPath(path, start)
Function to check, if a path starts with a given start path.
- path (str)
-
path to be checked
- start (str)
-
start path
- Return:
-
flag indicating that the path starts with the given start
path
- Return Type:
-
bool
toNativeSeparators
toNativeSeparators(path)
Function returning a path, that is using native separator characters.
- path (str)
-
path to be converted
- Return:
-
path with converted separator characters
- Return Type:
-
str