Skip to first unread message

TimAI2

unread,
Feb 3, 2019, 8:49:52 AM2/3/19
to mitappinv...@googlegroups.com
Someone else, somewhere else "may" want to do something like this......

The target platform is a raspberry Pi running raspbian (linux)

I needed to have a working csv file of a directory listing, in order for the app user to build their own directory path

On the raspberry Pi I ran the following commands

tree -dfi /home/tim/Original > original.csv

 to get from this:

/home/tim/Original
/home/tim/Original/One
/home/tim/Original/One/Two
/home/tim/Original/One/Two/Three
/home/tim/Original/One/Two/Three/Four

4 directories


sed -i 's/\//,/g' original.csv ##convert / to ,
sed -i 's/,home,tim,Original,//' original.csv ##remove string
sed -i '1d' original.csv ##remove first liine
sed -i '/^$/d' original.csv ##remove all empty lines
sed -i '$d' original.csv  ##remove last line
truncate -s -1 original.csv ##remove last line return

to this:

One
One,Two
One,Two,Three
One,Two,Three,Four

I now had a starting point for a csv file which I could upload to the app, but more work is needed to make it a workable csv

Needed to do three things:
1. Get the length of each "list" on each line in the file
2. Find the longest list of each of these lists  (Thanks to ABG for the code for this snippet)
3. Add the correct number of commas to the end of each line

BLOCKS (note: for convenience I recreated the "original.csv" file using text blocks called variable: oddcsv)
All the goodness happens in the procedure "pResolveCSV")

blocksresolvecsv.png


Once screen1.initialise is run, the resultant list is displayed on the app (for demonstration purposes) along with what the original file looked like, and the imported file
Converted to an from csv format used to show the added commas

SCREEN

screenresolvecsv.png

Now each line/list in the list of lists has the same number of fields, thus avoiding errors when iterating through the list


The initial conversion work done on the raspberry Pi could be done in the app as well


You never know, someone, somewhere......


Reply all
Reply to author
Forward
0 new messages