I want to write the filenames of a particular folder in a CSV file( for the purpose of bulk uploading to the Internet Archive). The CSV must be written in the prescribed format.
I have tried the following code :
import os
import csv
path = '/media/sarada/Lectures & Ebooks/Ebooks/03-Bengali Books/18.Darshan'
with open('/home/sarada/ia_csv.csv', 'wb') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['identifier', 'file', 'description', 'subject[0]', 'title', 'creator', 'date', 'collection'])
for dirpath, _, filenames in os.walk(path):
if filenames:
writer.writerow([os.path.basename(dirpath)] + filenames)
Now the file names are being printed in a row, i.e they are covering the description, title, creator etc. fields.
The issues:
File names should be printed in the
filecolumn only.How to print only the file name(stripping the extension portion) in
titlecolumn?How to add a string(e.g
opensource) in
writer.writerow([os.path.basename(dirpath)] + filenames)so that
thecreatorcolumn contains that string?