fileIO

@fileIO Module with custom file handling operations

geobipy.src.base.fileIO.bytes2readable(nBytes)

Convert bytes to KB, MB, …, PB

Parameters:

nBytes (float) – The number of bytes

Returns:

out – The number of KB, MB, etc.

Return type:

str

geobipy.src.base.fileIO.deleteFile(fname)

Deletes a file if it exists

Parameters:

fName (str) – A path and/or file name

geobipy.src.base.fileIO.dirExists(dirPath)

Check if a directory exists on disk

Parameters:

dirPath (str) – A directory path

Returns:

out – Whether the directory path exists

Return type:

bool

geobipy.src.base.fileIO.fileExists(fname)

Check if a single file exists on disk

Parameters:

fname (str) – A file name

Returns:

out – Whether the file exists or not

Return type:

bool

geobipy.src.base.fileIO.filesExist(fNames)

Check if all files in fNames exist on disk

Parameters:

fNames (list of str)

Returns:

out – Whether all files exist or not

Return type:

bool

geobipy.src.base.fileIO.getFileExtension(fname)

Gets the extension of the filename

Parameters:

fname (str) – A path and/or file name

Returns:

out – The extension of the filename

Return type:

str

geobipy.src.base.fileIO.getFileSize(fName)

Get the size of a file on disk

Parameters:

fName (str) – A path and/or file name

Returns:

out – The file size in KB, MB, etc.

Return type:

str

geobipy.src.base.fileIO.getNcolumns(fName, nHeaders=0)

Gets the number of columns in a file using the line after nHeaders

Parameters:
  • fName (str) – A path and/or file name

  • nHeaders (int, optional) – Number of header lines to skip before obtaining the number of columns

Returns:

out – The number of columns

Return type:

int

geobipy.src.base.fileIO.getNlines(fname, nHeaders=0)

Gets the number of lines in a file after taking into account the number of header lines

Parameters:
  • fName (str) – A path and/or file name

  • nHeaders (int, optional) – Subtract the number of header lines from the total number of lines in the file

Returns:

out – Number of lines without the headers

Return type:

int, optional

geobipy.src.base.fileIO.get_column_name(filename)

Read headers names from a line in a file

Parameters:
  • fName (str) – A path and/or file name.

  • i (in or list of ints, optional) – The indices of the entries to read from the string. By default, all entries are read in.

  • nHeaders (int, optional) – The number of header lines to skip in the file.

Returns:

out – A list of the parsed header entries.

Return type:

list of str

geobipy.src.base.fileIO.get_real_numbers_from_line(line, indices=None, delimiters=',')

Reads strictly the numbers from a string

Parameters:
  • line (str) – A string, or a line from a file.

  • i (in or list of ints, optional) – The indices of the entries to read from the string. By default, all entries are read in.

  • delimiters (str) – Splits the line based on these delimiters.

Returns:

out – The values read in from the string.

Return type:

numpy.ndarray

geobipy.src.base.fileIO.int2str(i, N)

Converts an integer to a string with leading zeros in order to maintain the correct order in the file system

Parameters:
  • i (int) – The integer to convert to a string.

  • N (int) – The maximum number of digits you wish to have in the integer. e.g. int2str(3,4)=’0003’.

Returns:

out – The integer padded with zeroes on the front.

Return type:

str

geobipy.src.base.fileIO.isFileExtension(fname, ext)

Check that the filename is of the given extension

Parameters:
  • fname (str) – A path and/or file name

  • ext (str) – The extension you want to check the file name against

Returns:

out – Whether the extension of fname matches ext

Return type:

bool

geobipy.src.base.fileIO.parseString(this, delimiters=',')

Parse a string into its entries

Parameters:
  • this (str) – The string to parse.

  • delimiters (str) – Patterns to split against, e.g. ‘,’ splits at every comma.

Returns:

out – A list of the parsed entries

Return type:

list of str

geobipy.src.base.fileIO.wccount(filename)

Count the number of lines in a file using a wc system call

Parameters:

fName (str) – A path and/or file name

Returns:

out – The number of lines in the file

Return type:

int