# eric7.SystemUtilities.FileSystemUtilities

Module implementing file system related utility functions.

### Global Attributes

None

### Classes

None

### 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.
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)

Up

## 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)

Up

## 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)

Up

## 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

Up

## 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

Up

## 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

Up

## 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

Up

## 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.

Up

## 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.

Up

## 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

Up

## 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.

Up

## 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

Up

## 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)

Up

## 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.

Up

## 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)

Up

## 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)

Up

## 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)

Up

## 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)

Up

## 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)

Up

## 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)

Up

## 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.

Up

## 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.

Up

## 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).

Up

## 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

Up

## 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

Up