fig shell: file command shell for certain tasks
#1
.....
Reply
#2
That looks similar to an MSDOS shell I put together to sort out old duplicates in other folders. 

As you know, in MSDOS you can get the date in the dir command but you have to convert it to year-month-day format to sort it. A three-dim array was used to store the uppercase file name, folder name and the restructured date. A simple sort routine was then used to first alphabetize the list. A second sort routine was then used to place the most recent date at the top of the sort of each duplicate. The display had an option to show all files and the folders they were in or just the most recent. I never got around to making a "click to open with" feature.

Pete Shy
Reply
#3
.
isoname .bas
isoname pete
sort256
each leafpad

-- no duplicates. each leafpad will open each of the files in leafpad:

the first one appears to be a screen 0 version of your first graphics program.
the second one appears to be the original, or closer to it.
the other one is more like the first, but different.

i can get rid of these. i will just type rm and paste the 3 names there. "each" only works on certain commands/programs, its a whitelist. i deliberately made it so that "each rm" wont do anything.
Reply
#4
I made a graphics program? Did I recover or am I still in rehab?

Pete Big Grin
Reply
#5
It's a shame you have to provide links to prove to some buttheads you don;t make things up. hat's one thing I can vouch for, for whatever that's worth.

Anyway, I vaguely remember that thread. I think that was around the time I got interested in pushing for QB64 to get into an Android platform. 

I also have some routines that have clickable hyperlinks in a QB app. I believe I incorporated links into one of my many WP routines. I guess I need to build a library some day. No, not a code one. I was thinking more along the lines of the one they build for Reagan. I was there when that one opened. On second thought, scrap that. I'd probably have to lose my koi pond to fit it in the yard.

Anyway, back to the dir stuff... I updated one of my old QB routines for QB64. It is a bare bones update but it does / should sort files and orders duplicates by date/time.

Code:
WIDTH 140, 43
_SCREENMOVE 0, 0
INPUT "Drive and path: "; mypath$
' Step 1 - Find the number of files to DIM array.
SHELL _HIDE "dir /A:-D /b " + mypath$ + " /s>tmp.txt"
OPEN "tmp.txt" FOR INPUT AS #1
DO UNTIL EOF(1)
    LINE INPUT #1, a$
    x = x + 1
LOOP
CLOSE #1
REDIM myfile$(x)

SHELL _HIDE "dir /A:-D " + mypath$ + " /s>tmp.txt"
OPEN "tmp.txt" FOR INPUT AS #1
DO UNTIL EOF(1)
    LINE INPUT #1, a$
    ' Step 2 - ID directories.
    IF INSTR(UCASE$(a$), "DIRECTORY OF ") THEN
        myfolder$ = RTRIM$(MID$(a$, INSTR(UCASE$(a$), "DIRECTORY OF ") + 13))
    END IF

    IF MID$(a$, 3, 1) = "/" THEN
        ' Step 3 - Convert date.
        mydate$ = MID$(a$, 7, 4) + MID$(a$, 1, 2) + MID$(a$, 4, 2)
        ' Step 4 - Convert to Army Time.
        mytime$ = MID$(a$, 13, 8)
        ampm$ = RIGHT$(mytime$, 2)
        SELECT CASE UCASE$(ampm$)
            CASE "AM"
                IF MID$(mytime$, 1, 2) <> "12" THEN
                    mytime$ = MID$(mytime$, 1, 2) + MID$(mytime$, 4, 2)
                ELSE
                    mytime$ = LTRIM$(STR$(12 + VAL(MID$(mytime$, 1, 2)))) + MID$(mytime$, 4, 2)
                END IF
            CASE "PM"
                IF MID$(mytime$, 1, 2) <> "12" THEN
                    mytime$ = LTRIM$(STR$(12 + VAL(MID$(mytime$, 1, 2)))) + MID$(mytime$, 4, 2)
                ELSE
                    mytime$ = MID$(mytime$, 1, 2) + MID$(mytime$, 4, 2)
                END IF
            CASE ELSE
                PRINT "Error in ampm$ conversion: "; ampm$: END ' SYSTEM
        END SELECT

        ' Step 5 - place date, time, name, and folder in an array.
        cnt = cnt + 1
        PRINT cnt
        myfile$(cnt) = RTRIM$(MID$(a$, 40)) + "^" + mydate$ + mytime$ + "|" + myfolder$
    END IF
LOOP
CLOSE #1

' Step 6 Sort to alphabertize and get latest version by date.
FOR i = 1 TO x
    FOR j = 1 TO x
        IF i <> j THEN
            IF UCASE$(myfile$(i)) < UCASE$(myfile$(j)) THEN SWAP myfile$(i), myfile$(j)
        END IF
    NEXT
NEXT

FOR i = 1 TO x
    COLOR 7, 0: PRINT "File: ";
    COLOR 15, 0: PRINT LCASE$(MID$(myfile$(i), 1, INSTR(myfile$(i), "^") - 1));
    COLOR 7, 0: PRINT " in folder: ";
    COLOR 14, 0: PRINT MID$(myfile$(i), INSTR(myfile$(i), "|") + 1)
NEXT
Now the thing is when you get to thousands of file, you would want it printed to a text file but this is just a demo so I left that out. Also, this is a very basic slow sorting routine. It is fine for a few hundred files but too slow for thousands. I wish I could find my old Fruit Sort submission on the QB Forum. N54 F'ed up the search feature recently Sad

Pete Smile
Reply
#6
Quote:It's a shame you have to provide links

well, links are good. incidentally the only reason i was writing a "book" was to demonstrate some of my ideas in detail. its not like i was planning to try to sell that thing (just the ideas.)

speaking of dir stuff, you can try this in qb64: http://www.network54.com/Forum/190883/me...ew+version

and speaking of links, what do you think of this one?

http://www.network54.com/Forum/202193/me...+the+fruit!
Reply
#7
Wow, that was a trip down memory lane. Nice of you to find that! I spent some time looking at the various posts associated with that challenge. I got a kick out of the reply to Moneo, who started the challenge: Give it up...your submission is fruitless! You will be assimilated.  That, and the Fruit LOOPS bit. I'll have to substitute that in and see if it flies any faster than what I posted here. I also want to have a look at some of Codeguys stuff. What he lacks in parallel parking skills he makes up in sort routines.

Pete Big Grin
Reply
#8
version 0.2 has--
in addition to isoname (isolate by name):
it has minusname (remove by name from list, doesnt affect files)
and isoplus (which is like grep, and currently uses grep)

so you can limit the list to just .png/.jpg/.gif, remove anything with an underscore:
isoname .png|.jpg|.gif
minusname _
and open each with gpicview:
each gpicview

you can do all of this with bash, but there are advantages to doing this with python or fig.

isoname .txt
each leafpad

Code:
#### license: creative commons cc0 1.0 (public domain)
#### http://creativecommons.org/publicdomain/zero/1.0/

proginf "figsh 0.2, oct 2017 mn" print
now "" print

cmd command join cmd " "

function getlist cmd
    find "find -type f"
    cmdlen cmd len
    iftrue cmdlen
        find "find " plus cmd plus " -type f"
        fig
    quot 34 chr
    p  find            arrshell
    x  p               len       minus 1
    p  left x          return p
    fig


function isoname p f
    quot 34 chr
    fs split f "|"
    plen p len
    psub " " arr times plen
    pc 0
    c 0
    
    forin s p
        now  c   plus 1  swap now c
        #now  "sha256sum " plus quot  plus x  plus quot  arrshell  mid 1 1
        forin fsf fs
            subs instr s fsf
            iftrue subs
                now pc plus 1 swap now pc
                psub arrset pc s
                break
                fig
            next
        fig

    psub  left pc          return psub
    fig

function isoplus p f
    quot 34 chr
    fs split f "|"
    plen p len
    psub " " arr times plen
    pc 0
    c 0
    
    forin x p
        now  c   plus 1  swap now c
        #now  "sha256sum " plus quot  plus x  plus quot  arrshell  mid 1 1
        forin fsf fs
            equot 92 chr plus quot
            efsf split fsf quot join efsf equot
            subs "grep " plus quot  plus efsf  plus quot plus " " plus quot plus x plus quot plus " | wc -l"  arrshell  mid 1 1 val
            iftrue subs
                now pc plus 1 swap now pc
                psub arrset pc x
                break
                fig
            next
        fig

    psub  left pc          return psub
    fig



function minusname p f
    quot 34 chr
    fs split f "|"
    plen p len
    psub " " arr times plen
    pc 0
    c 0
    
    forin s p
        now  c   plus 1  swap now c
        #now  "sha256sum " plus quot  plus x  plus quot  arrshell  mid 1 1
        fsfcount 0
        forin fsf fs
            subs instr s fsf
            iftrue subs
                fsfcount 1
                break
                fig
            next
        ifequal fsfcount 0
            now pc plus 1 swap now pc
            psub arrset pc s
            fig
        fig

    psub  left pc          return psub
    fig


function doeach p f
    quot 34 chr
    plen p len
    #psub " " arr times plen
    pc 0
    c 0
    
    v "leafpad geeqie gpicview ls du xdg-open evince xpdf mtpaint" split v " " instr v f
    iftrue v
        forin x p
            now  c   plus 1  prints swap now c " " prints
            now x print
            now  f plus " " plus quot  plus x  plus quot plus " 2> /dev/null" shell
            fig
        fig
    fig


function putlist p s f
    quot 34 chr
    c 0
    plen p len
    ifmore s f
        now swap s f
        fig
    ifmore f plen
        f plen
        fig    
    sminus s minus 1
    fminus f minus 1
    forin x p
        ifmore s 0
            ifless c sminus
                now  c   plus 1  swap now c
            else
                ifmore c fminus
                    now  c   plus 1  swap now c
                else
                    now  c   plus 1  prints  swap now c
                    now  " " prints
                    now  x   print
                    fig
                fig
        else
            now  c   plus 1  prints  swap now c
            now  " " prints
            now  x   print
            fig
        next
        fig


function sumlist p s f sum
    quot 34 chr
    c 0
    plen p len
    ifmore s f
        now swap s f
        fig
    ifmore f plen
        f plen
        fig    
    sminus s minus 1
    fminus f minus 1
    forin x p
        ifmore s 0
            ifless c sminus
                now  c   plus 1  swap now c
            else
                ifmore c fminus
                    now  c   plus 1  swap now c
                else

                    ifequal sum "-"
                        now  c   plus 1  prints  swap now c
                        now  " " prints
                        now  "sha256sum " plus quot  plus x  plus quot  arrshell  mid 1 1  print
                    else
                        now  c   plus 1  swap now c
                        try
                            get256  "sha256sum " plus quot  plus x  plus quot  arrshell  mid 1 1  left 64
                            ifequal get256 sum
                                now c prints " " prints
                                now x prints " " prints get256
                                fig
                        except
                            get256 ""
                            resume
                        fig

                    fig
                fig
        else
            now  c   plus 1  prints  swap now c
            now  " " prints
            now  x   print
            fig
        next
        fig



function sortlist p s f sum
    quot 34 chr
    c 0
    plen p len
    ifmore s f
        now swap s f
        fig
    ifmore f plen
        f plen
        fig    
    sminus s minus 1
    fminus f minus 1
    psort " " arr times plen  
    c 0
    forin x p
        now  c   plus 1  swap now c
        now  "sha256sum " plus quot  plus x  plus quot  arrshell  mid 1 1
        psort arrset c now
        fig
    psort arrsort
    c 0
    forin x psort
        ifmore s 0
            ifless c sminus
                now  c   plus 1  swap now c
            else
                ifmore c fminus
                    now  c   plus 1  swap now c
                else

                    ifequal sum "-"
                        now  c   plus 1  prints  swap now c
                        now  " " prints
                        now  x  print
                    else
                        now  c   plus 1  swap now c
                        try
                            get256  "sha256sum " plus quot  plus x  plus quot  arrshell  mid 1 1  left 64
                            ifequal get256 sum
                                now c prints " " prints
                                now x prints " " prints get256
                                fig
                        except
                            get256 ""
                            resume
                        fig

                    fig
                fig
        else
            now  c   plus 1  prints  swap now c
            now  " " prints
            now  x   print
            fig
        next
        fig


function sortdu p s f sum
    quot 34 chr
    c 0
    plen p len
    ifmore s f
        now swap s f
        fig
    ifmore f plen
        f plen
        fig    
    sminus s minus 1
    fminus f minus 1
    psort " " arr times plen  
    c 0
    forin x p
        now  c   plus 1  swap now c
        tab 9 chr
        now  "du -b " plus quot  plus x  plus quot  arrshell  mid 1 1 split now tab mid 1 1
        du 32 chr times 11 plus now right 11 plus " " plus x
        psort arrset c du
        fig
    psort arrsort
    c 0
    forin x psort
        ifmore s 0
            ifless c sminus
                now  c   plus 1  swap now c
            else
                ifmore c fminus
                    now  c   plus 1  swap now c
                else

                    ifequal sum "-"
                        now  c   plus 1  prints  swap now c
                        now  " " prints
                        now  x  print
                    else
                        now  c   plus 1  swap now c
                        try
                            get256  "du -b " plus quot  plus x  plus quot  arrshell  mid 1 1  left 64
                            ifequal get256 sum
                                now c prints " " prints
                                now x prints " " prints get256
                                fig
                        except
                            get256 ""
                            resume
                        fig

                    fig
                fig
        else
            now  c   plus 1  prints  swap now c
            now  " " prints
            now  x   print
            fig
        next
        fig




quot 34 chr
plist ""

while

while
    p    colortext 10  ""            prints  lineinput  ltrim  rtrim
    lc   p             lcase    
    plen p             len          
    now  colortext 7   ""            prints

    ifequal lc "q"
        break
        fig
    ifequal lc "?"
        now colortext 7 ""                    print
        now " q to quit"                      print
        now " ? for help"                     print
        now " pwd to print working directory" print
        now " . to update"                    print
        now ""                                print
        now " each: leafpad geeqie gpicview ls du xdg-open evince xpdf mtpaint" print
        now " shell: rm cat 256 ls"           print
        now " r to refresh"                   print
        now " r top bottom: specify range "   print
        now ""                                print
        now " dup name: find sha256sum duplicates of name"     print
        now " isoname name: restrict list to what contains name"    print
        now " minusname what: remove names from list by partial string (doesnt affect files)"    print
        now " isoplus what: restrict list to files that include what (grep-like)"    print
        now " sort256: do sha256sum for all entries, sorted"   print
        now " with256: do sha256sum for all entries, unsorted" print
        now " sortdu: do du -b for all entries, sorted"   print
        now ""                                print
        break
        fig
    ifequal lc "pwd"
        now colortext 7 "pwd" arrshell mid 1 1 print
        break
        fig
    ifmore plen 4
        pleft lc left 4
        ifequal pleft "256 "
            pright plen minus 3
            now  p  right pright  reverse  plus "mus652ahs"  reverse  shell
            break
            fig
        fig
    ifmore plen 4
        pleft lc left 4
        ifequal pleft "dup "
            pright plen minus 3
            sum  p  right pright  ltrim  rtrim  plus quot  reverse  plus quot plus " mus652ahs"  reverse arrshell mid 1 1
            try
            now sum  left 64 print swap now sum
            plistlen plist len
            p colortext 7 "" prints sumlist plist 1 plistlen sum
            except
            sum ""
            resume
            now "" print "dup check complete" print
            break
            fig
        fig
    ifmore plen 8
        pleft lc left 8
        ifequal pleft "isoname "
            plenminus plen minus 8
            pright lc right plenminus
            try
            plistlen plist len
            p colortext 7 "" prints
            plist isoname plist pright  putlist plist -1 -1
            except
            plistlen
            resume
            now "" print "isoname complete" print
            break
            fig
        fig
    ifmore plen 8
        pleft lc left 8
        ifequal pleft "isoplus "
            plenminus plen minus 8
            pright lc right plenminus
            try
            plistlen plist len
            p colortext 7 "" prints
            plist isoplus plist pright  putlist plist -1 -1
            except
            plistlen
            resume
            now "" print "isoname complete" print
            break
            fig
        fig
    ifmore plen 10
        pleft lc left 10
        ifequal pleft "minusname "
            plenminus plen minus 10
            pright lc right plenminus
            try
            plistlen plist len
            p colortext 7 "" prints
            plist minusname plist pright  putlist plist -1 -1
            except
            plistlen
            resume
            now "" print "minusname complete" print
            break
            fig
        fig
    ifmore plen 3
        pleft lc left 3
        ifequal pleft "rm "
            now p shell
            lc "."
            fig
        fig
    ifmore plen 4
        pleft lc left 4
        ifequal pleft "cat "
            now p shell
            break
            fig
        fig
    ifmore plen 5
        pleft lc left 5
        ifequal pleft "each "
            now split p " " mid 2 1  
            try
                plistlen plist len
            except
                plistlen
                plist ""
                fig
                p colortext 7 "" prints doeach plist now
                break
            fig
        fig
    ifmore plen 3
        pleft lc left 3
        ifequal pleft "ls "
            now p shell
            break
            fig
        fig
    ifmore plen 2
        pleft lc left 2
        ifequal pleft "r "
            r split p " "
            rlen r len
            ifmore rlen 2
            try
                s  r  mid 2 1  val
                f  r  mid 3 1  val
                now colortext 7 "" prints putlist plist s f
            except
                r
                resume
            break
            fig
            fig
        fig
    ifequal lc "."
        plist colortext 7 "" prints getlist cmd putlist plist -1 -1
        break
        fig
    ifequal lc "r"
        try
            plistlen plist len
        except
            plistlen
            plist ""
            fig
        p colortext 7 "" prints putlist plist 1 plistlen
        break
        fig

    ifequal lc "with256"
        try
            plistlen plist len
        except
            plistlen
            plist ""
            fig
        p colortext 7 "" prints sumlist plist 1 plistlen "-"
        break
        fig

    ifequal lc "sort256"
        try
            plistlen plist len
        except
            plistlen
            plist ""
            fig
        p colortext 7 "" prints sortlist plist 1 plistlen "-"
        break
        fig

    ifequal lc "sortdu"
        try
            plistlen plist len
        except
            plistlen
            plist ""
            fig
        p colortext 7 "" prints sortdu plist 1 plistlen "-"
        break
        fig

    now colortext 7   "? for help"  print
    wend

    ifequal lc "q"
        now "" print
        break
        fig
    wend
Reply