Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

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
end
File.open('output.csv', 'w') do |f|
    f.puts table.map {|row| CSV.generate_line(row) }.join("\n")
end

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

calc CSV import

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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