Method: FileSystem.path_pieces

Defined in:
lib/atk/file_system.rb

.path_pieces(path) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'lib/atk/file_system.rb', line 269

def self.path_pieces(path)
    # use this function like this:
    # *path, filename, extension = FS.path_pieces('/Users/jeffhykin/Desktop/place1/file1.pdf')
    pieces = Pathname(path).each_filename.to_a
    extname = File.extname(pieces[-1])
    basebasename = pieces[-1][0...(pieces[-1].size - extname.size)]
    # add the root if the path is absolute
    if FileSystem.abs?(path)
        if not OS.is?("windows")
            pieces.unshift('/')
        else
            # FUTURE: eventually make this work for any drive, not just the current drive
            pieces.unshift('\\')
        end
    end
    return [ *pieces[0...-1], basebasename, extname ]
end