FileSystem.jl

This module implements utilities for working with files and directories.

It is a complement to the standard Julia FileSystem module.

FunctionDescription
Eegle.FileSystem.fileBaseget a file path without the extension
Eegle.FileSystem.fileExtextract the extension from a file name, including the dot
Eegle.FileSystem.changeFileExtchange the extension of a file
Eegle.FileSystem.getFilesInDirsearch for files in a directory and its subdirectories
Eegle.FileSystem.getFoldersInDirsearch for directories in a directory and its subdirectories

📖

Eegle.FileSystem.fileBaseFunction
    function fileBase(file::String)

Return file, including the complete path, without the extension.

basename

Julia's basename function returns instead the file name with no path and with extension

Example

fileBase(joinpath(homedir(), "myfile.txt"))
# return (joinpath(homedir(), "myfile"))
source
Eegle.FileSystem.fileExtFunction
    function fileExt(file::String)

Return the extension of a file, including the dot.

Example

fileExt(joinpath(homedir(), "myfile.txt")) 
# return ".txt" 
source
Eegle.FileSystem.changeFileExtFunction
    function changeFileExt(file::String, ext::String)

Return the complete path of file with extension changed to ext.

Example

changeFileExt(joinpath(homedir(), "myfile.txt"), ".csv") 
# return joinpath(homedir(), "myfile.csv")
source
Eegle.FileSystem.getFilesInDirFunction
    function getFilesInDir(dir::Union{String, Vector{String}}; 
        ext::Tuple=(), isin::String="")

Return a vector of strings comprising the complete path of all files in directory dir.

Arguments

  • dir, which can be a directory or a vector of directories.

Optional Keyword Arguments

  • ext is an optional tuple of file extensions. If it is provided, return only the files with those extensions. The extensions must be entered in lowercase.
  • If a string is provided as isin, return only those files whose name contains the string.

Examples

using Eegle # or using Eegle.FileSystem

S=getFilesInDir(@__DIR__) # start at current directory.

S=getFilesInDir(@__DIR__; ext=(".txt", ))

S=getFilesInDir(@__DIR__; ext=(".txt", ".jl"), isin="Analysis")
source
Eegle.FileSystem.getFoldersInDirFunction
    function getFoldersInDir(dir::String; isin::String="")

Return a vector of strings comprising the complete path of all directories in directory dir.

If a string is provided as kwarg isin, return only the directories whose name contains the string.

Examples

using Eegle # or using Eegle.FileSystem

S=getFoldersInDir(@__DIR__)

S=getFoldersInDir(@__DIR__; isin="Analysis")
source