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.fileBase โ€” Function
function fileBase(file::String)

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

Return file if it has no extension.

file does not need to exist.

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.fileExt โ€” Function
    function fileExt(file::String)

Return the extension of a file, including the dot.

Example

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

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

If file has no extension, add it.

file does not need to exist.

Example

changeFileExt(joinpath(homedir(), "myfile.txt"), ".csv") 
# return joinpath(homedir(), "myfile.csv")

changeFileExt(joinpath(homedir(), "myfile"), ".csv") 
# return joinpath(homedir(), "myfile.csv")
source
Eegle.FileSystem.getFilesInDir โ€” Function
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.getFoldersInDir โ€” Function
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