filelib

package module
v1.0.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 9 Imported by: 50

README

filelib

license

Go (golang) miscellaneous file and templating routines

A library of convenience functions for dealing with files.

func Exists(name string) bool {

Return true if file exists.

func GetFilenames(dir string) (filenames, dirs []string) {

GetFilenames gets a list of file names and directorys.

func ExistsIsDir(name string) bool {

Returns true if name exists and is a directory.

func InArray(lookFor string, inArr []string) bool {

Returns true if lookFor is in the array inArr. A more general form of this is in the pluto library that uses generics.

func InArrayN(lookFor string, inArr []string) int {

Searches the array inArr for lookFor returning the position if found, or -1 if not found.

func InArrayInt(lookFor int, inArr []int) bool {

Searches the array of int inArr for the value lookFor returning true if found.

func AllFiles(path, match string) (fns, dirs []string) {

Recursively searches for all the files in a path.

Documentation

Overview

Copyright (C) Philip Schlump, 2013-2016. Version: 1.0.3 Tested on Mon Jun 20 18:01:48 MDT 2016

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllFiles added in v1.0.3

func AllFiles(path, match string) (fns, dirs []string)

AllFiles returns a recursive list of all files (excluding all directories). Empty directories will be eliminated. Passing an empty string for match will return all files, but faster, skiping the regular expression pattern match.

func ApplyFilenames added in v1.0.2

func ApplyFilenames(dir string, fx ApplyFilenamesFunc) (filenames, dirs []string)

func CleanupOldFiles added in v1.0.2

func CleanupOldFiles(dir string, dt time.Duration)

func Exists

func Exists(name string) bool

Exists reports whether the named file or directory exists.

func ExistsIsDir added in v1.0.2

func ExistsIsDir(name string) bool

ExistsIsDir returns true if the directory exists.

func FilterArray added in v1.0.3

func FilterArray(re string, inArr []string) (outArr []string)

func Fopen

func Fopen(fn string, mode string) (file *os.File, err error)

Fopen opens a file with a mode string - similar to C fopen

func GetFilenames added in v1.0.1

func GetFilenames(dir string) (filenames, dirs []string)

GetFilenames gets a list of file names and directories. The directories '.' and '..' are removed. Other '.[.]?.*' fiels and directories are included.

func InArray added in v1.0.3

func InArray(lookFor string, inArr []string) bool

InArray returns true if `lookFor` is found in `inArr`.

func InArrayInt added in v1.0.6

func InArrayInt(lookFor int, inArr []int) bool

InArrayInt returns true if the interger lookFor isfound in the int slice inArr.

func InArrayN added in v1.0.3

func InArrayN(lookFor string, inArr []string) int

InArrayN returns the position if `lookFor` is found in `inArr`, else -1.

func InPatternArray added in v1.0.9

func InPatternArray(s string, pat []string) (rv int, err error)

InPatternArray seqrches a set of regular expression patterns in 'pat' and sees if any match. -1 is returned if no match.

func Qt

func Qt(format string, data map[string]string) string

Qt is a string quick template. %{name%} gets replace with substitution from map if it is in map, else ""

func QtR

func QtR(format string, data map[string]interface{}) string

QtR is a string quick template. It uses the same format as Qt but you get to pass a map[string]interface{}

func RemoveMatch added in v1.0.7

func RemoveMatch(re string, inArr []string) (outArr []string)

func ReplaceExt added in v1.0.8

func ReplaceExt(fn string, newExt string) (out string)

func RmExt

func RmExt(filename string) string

RmExt remove the extension from a file name and returns the name.

func SearchPathApp

func SearchPathApp(rawFileName string, appName string, searchPath string) (fullFileName string, ok bool)

SearchPathApp searches a set of paths for a particular file.

func SubstitueUserInFilePath

func SubstitueUserInFilePath(s string, mdata map[string]string) (rs string, has bool)

SubstitueUserInFilePath looks up the user and replaces '~' or '~name' whith the home direcotry

Types

type ApplyFilenamesFunc added in v1.0.2

type ApplyFilenamesFunc func(ty string, fn string, fstat os.FileInfo)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL