Class: Util::FS

Inherits:
Object
  • Object
show all
Defined in:
lib/utilities/utils.rb

Overview

B.2. FILE SYSTEM ————————————————————————————————

Instance Method Summary collapse

Instance Method Details

#clear_directory(path) ⇒ Object

B.2.2. CLEAR THE ENTIRE DIRECTORY



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/utilities/utils.rb', line 111

def clear_directory(path)
    
    msg = Util::Message.new()

    if isEmpty(path)

        msg.warning("Your directory isn't empty! Konstruct can only be installed in an empty directory.");

        puts Paint["----------------------------------------------------------------------------", :yellow]

        puts ""
        puts Paint["DIRECTORY LISTING: #{path}", :yellow] 
        puts ""
        puts Paint[Dir.entries(path), :yellow]
        puts ""

        puts Paint["----------------------------------------------------------------------------", :yellow]

        puts ""

        choice = choose("Do you want to clear your working directory?", :yes, :no)

        if choice == :yes 
            
            toClear = "#{path}/*"
            
            FileUtils.rm_rf(Dir.glob(toClear))

            msg.success("Working directory cleared: #{path}")

        else

            msg.error("Konstruct can only be installed in an empty directory.")
            exit(1)

        end

    end
    
end

#isEmpty(path) ⇒ Object

B.2.1. CHECK FOR EMPTY DIRECTORY



93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/utilities/utils.rb', line 93

def isEmpty(path)
   
    if Dir.entries(path).length > 2
   
        result = true

    else
        
        result = false
        
    end
    
end