How can I automatically create a list of files and folders in a given folder in LibreOffice Calc ? I'd like it to have as much info as possible (size, name, folder hierarchy...) sorted in nice little cells. I'd rather not dump it to a file using ls and then trying to sort it manually: it creates an awful output.


Your best bet would be to use a scripting language (Ruby, Python, Perl etc.) to create a text file in CSV format with this data. Calc can import CSV text files as spreadsheets.

An example Ruby script to get you started:

#!/usr/bin/env ruby
require 'csv'
table = [['Name', 'Size', 'Path']] #These are your headings - you can change them
Dir['./*'].each do |file|
    table << [File.basename(file), File.size(file), File.expand_path(file)]
    #You can add extra columns with extra information in the above line
File.open('output.csv', 'w') do |f|
    f.puts table.map {|row| CSV.generate_line(row) }.join("\n")

Run this in the appropriate directory then open the file 'output.csv' with Calc. Use the following settings on the import:

calc CSV import

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.