helperSystem.jl 1.45 KB
Newer Older
1 2 3

import Glob

William F Godoy's avatar
William F Godoy committed
4 5 6 7 8 9 10 11 12 13
"""
  Gets the list of directories with a certain absolute prefix
  
  Example:
     /my/absolute/path/prefix
     returns:
     /my/absolute/path/prefix.1
     /my/absolute/path/prefix.2
     /my/absolute/path/prefix.3
"""
14
function helper_get_prefix_directories(prefix::String)::Array{String}
William F Godoy's avatar
William F Godoy committed
15 16 17 18 19 20 21 22 23 24
    findDelimiter = findlast("/", prefix)
    searchDirectory::String = prefix[1:findDelimiter[1]-1]
    #print(searchDirectory)

    pattern::String = string(prefix[findDelimiter[1]+1:end], "*")
    outputDirs = Glob.glob(pattern, searchDirectory)
    return outputDirs
end


William F Godoy's avatar
William F Godoy committed
25 26 27 28 29 30 31 32 33 34 35 36
function helper_get_relative_path(fullName::String)::String
    findDelimiter = findlast("/", fullName)
    
   # if findDelimiter == Nothing
   #   return fullName
   # end  
    
    relativeName = string(fullName[findDelimiter[1]+1:end])
    return relativeName
end


William F Godoy's avatar
William F Godoy committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
"""
  Gets the list of files inside a path that meet the prefix criteria.
  Example: 
      path/prefix.*

      path/
           prefix.1
           prefix.2
           prefix.3

  output: [ prefix.1, prefix.2, prefix.3 ] 
"""
function helper_get_prefix_files(prefix::String, path::String)::Array{String}

    pattern::String = string(prefix, "*")
    files = Glob.glob(pattern, path)
William F Godoy's avatar
William F Godoy committed
53
    return files
William F Godoy's avatar
William F Godoy committed
54
end
William F Godoy's avatar
William F Godoy committed
55 56 57 58 59 60 61 62 63 64


function helper_get_directory_size(directory::String)::Int64

    size::Int64 = 0
    for (root, dirs, files) in walkdir(directory)
        size += sum(map(filesize, joinpath.(root, files)))
    end
    return size
end