It is currently Fri May 26, 2017 7:25 pm



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: array.binarysearch
Unread postPosted: Mon Apr 04, 2016 1:26 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5518
Location: Paris, France
I bounce back on my last post... Here is a not so complex functionality I want to implement: I want to get all non-hidden folders in /sdcard into an array.

First I list all files and folders (and append "/" at the end of folders), easy: FILE.DIR "../..", files$[], "/"

Then I remove all files: since FILE.DIR returns an array composed of folders first followed by files, I find the first file in the array, (let's call this index 'firstFile' = files$[firstFile] doesn't finish with "/") and I create a new array of only folders with ARRAY.COPY files$[1, firstFile-1], folders$[] (+I can undim files$[] for best memory management).

Now I want to get rid of "hidden" (system) folders, i.e. folders starting with "." then I need to create a list, copy the folders$[] array to it, scan all elements of the list and remove those who start with ".", undim the array folders$[], dump the list to it with LIST.TOARRAY, and clear the list to release unused memory.

Result of the operation: 2 arrays, 1 list, 1 array-to-array copy, 1 array-to-list copy, 1 list-to-array copy, 2 array-deletions, 1 list-deletion.

If it was possible to redim (preserve) an array and remove elements from an array, I would only have to deal with 1 array, period.

Marc, how do you think? Is this feasible?

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: array.binarysearch
Unread postPosted: Mon Apr 04, 2016 6:35 am 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 327
Nicolas,
I agree to your message last before.
But why re-arrange?
Which double item do you want to kill?
The first, the second, ....?

- Gregor


Report this post
Top
 Profile  
 
 Post subject: Re: array.binarysearch
Unread postPosted: Mon Apr 04, 2016 7:05 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5518
Location: Paris, France
I want to be able to remove an element of an array, the same way we can remove an element of a list.
After we have that, it's the programmer's duty to scan for doubles and remove which one he/she wants ;)

Nicolas

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: array.binarysearch
Unread postPosted: Mon Apr 04, 2016 9:41 am 
Offline
User avatar

Joined: Sun Nov 23, 2014 8:15 am
Posts: 2185
Location: romania
in MSDOS we have "dir /s" to list all subdirs. can't it be used as a system command in Andro?


Report this post
Top
 Profile  
 
 Post subject: Re: array.binarysearch
Unread postPosted: Mon Apr 04, 2016 9:50 am 
Offline
User avatar

Joined: Tue Jan 03, 2012 9:31 am
Posts: 5518
Location: Paris, France
In Linux its "ls -R" or "find ."
But you can do it with BASIC! command, see my recent program here: masch-move-all-subfolders-content-here-t4147.html and especially the function ListRecursiveFiles(path$, list)

...but what's the link with the subject at hand?

_________________
- Creator of the Android BASIC! Compiler


Report this post
Top
 Profile  
 
 Post subject: Re: array.binarysearch
Unread postPosted: Thu Dec 15, 2016 2:13 pm 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 327
What is with the keys of a Bundle?

FOR i = 1 TO 12
BUNDLE.PUT bP, key$[i], "blabla"
NEXT i

With
BUNDLE.KEYS bP, lP
we get a shortened list of strings with unique items.



Gregor


Report this post
Top
 Profile  
 
 Post subject: Re: array.binarysearch
Unread postPosted: Sun Dec 18, 2016 2:06 pm 
Offline
User avatar

Joined: Sun Nov 23, 2014 8:15 am
Posts: 2185
Location: romania
did anybody initialize key$[i] or are all the same value (key="")?


Report this post
Top
 Profile  
 
 Post subject: Re: array.binarysearch
Unread postPosted: Sun Dec 18, 2016 2:23 pm 
Offline
User avatar

Joined: Wed Jul 10, 2013 8:11 am
Posts: 327
Hi Gikam,

gikam wrote:
did anybody initialize key$[i] or are all the same value (key="")?


A bundle key have to be a single string.
An empty string is a valid value.
But only using "" made in my view no sense, because the value is overwriten every time.

The value for the given key in this special case can be the same.

See also at http://rfobasic.freeforums.org/deleting-unused-functions-in-gw-lib-t4782.html
the second code.

Gregor


Report this post
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred