B4A Library FileSelect Library With Type Icons

Attached is Version 1.02 of my File Selecting library. It includes type icons for most every type of file, creates a selection list which can be collected and produces thumbnails on the fly of image files. Copy the .jar and .xml file to your XtraLibs folder.

Requires: Reflections Library 2.4+, the Reflection lib does not need to be checked in the Libs tab but must be included in your XtraLibs folder or whatever path you have set for them.

Thanks to Stevel05 it moves more swiftly throughout!

Below are a few screen shots and some sample code.

B4X:
Sub Globals
    Dim FS As FileSelect
    FS.Initialize(Activity, Me, True, 0dip, 0dip, 500dip, 600dip)
End Sub
Sub Activity_Create(FirstTime As Boolean)
    FS.ShowFiles("/mnt")
End Sub
 
'Be sure to include this sub in your Activity. This sub
'is called by the Library once a file is selected.
Sub File_Selected(FileName As String, PathAndFile As String)
    Msgbox(FileName, PathAndFile)
End Sub
 

Attachments

  • FileSelect Ver. 1.02.zip
    193.5 KB · Views: 1,114
  • fs1.png
    fs1.png
    124.4 KB · Views: 1,196
  • fs2.png
    fs2.png
    37.5 KB · Views: 982
Last edited:

merlin2049er

Well-Known Member
Licensed User
Longtime User
I'll post some code tonight. I'm getting file not found. It looks like it's sticking in an extra \ (or /) in front of my mount point.
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Ok. here's part of my cut code, copy code is similar (without the remove).

B4X:
If  Cut.checked = True Then

'Msgbox("You clicked on...",FS.LongClickSelection)
'Msgbox(FS.LastPathUsed,"Last Path Used")
'Msgbox(filename, "file split function")

'Msgbox(FS.PathOnly, "Path Only")
Dim src, dst As String
src = FS.LongClickSelection
dst = FS.LastPathUsed & "/" & GetFileName(FS.LongClickSelection)

'dst = FS.LastPathUsed & "/" & GetFileName(FS.LongClickSelection)

If ml.cp(src, dst) = True Then
    ToastMessageShow("File pasted...", True)
Else
    Msgbox(ml.FSerror,"Error")
End If

If ml.rm(src) = True Then
    ToastMessageShow("File removed...", True)  
Else
    Msgbox(ml.FSerror,"Error")
End If


'FS.Invalidate_FilesList

End If 

Sub GetFileName(FullPath As String) As String
   Return FullPath.SubString(FullPath.LastIndexOf("/")+1)
End Sub
 

margret

Well-Known Member
Licensed User
Longtime User
I can't run the code you have but this code below has all you will need. I added this for your use:

B4X:
Sub File_Selected_LongClick(PathWithFileName As String, IsDirectory As Boolean)
    Log("Path & Name: " & PathWithFileName)
    Log("Is Directory: " & IsDirectory)
    Log("Last Path: " & FS.LastPathUsed)
    Log("Path With New Name:" & FS.LastPathUsed & "/newfilename.txt")
End Sub

See my log results here:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Path & Name: /mnt/ext_sdcard/My Files/Videos/Beastly_HQ.jpg
Is Directory: false
Last Path: /mnt/ext_sdcard/My Files/Videos
Path With New Name:/mnt/ext_sdcard/My Files/Videos/newfilename.txt

With that one sub you have all you need to delete, copy or rename any file.
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
ok, i'm using ml files along with the fs library.

For some odd reason, ml.cp gives me no such tool?

And when I use ml.rm (to delete a file) it returns no such file, doesn't like the spaces in the path/filename.

I tried to enclose it with '', but no luck.

hmm.
 

Douglas Farias

Expert
Licensed User
Longtime User
margret

1° question: is posible to change the buttons and blue bar colors and images?
2° is posible show only folders to open and images files?
.png .jpg etc etc?
 
Last edited:

merlin2049er

Well-Known Member
Licensed User
Longtime User
Just curious, I had the single click file sub routine in my app, but nothing in it.

What happens when the event is there and nothing in between (no code).
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
hmm, file select is reacting to a single click even though I don't have a single click event in my app for it.

It's turning black. :( Is there a way to prevent it from handling single clicks on the file system?
 

merlin2049er

Well-Known Member
Licensed User
Longtime User
Should I make a call to FS.ShowFiles(currentpath) to keep the fs active? After I've single clicked on a file, it disappears (after this msgbox (testing purposes only)).

B4X:
Sub File_Selected(FileName As String, PathAndFile As String)
    Msgbox(FileName, PathAndFile)
    'FS.Invalidate_FilesList    'Causes the view to reload and redraw
End Sub
 

ChrisH

Member
Licensed User
Longtime User
I forgot to show this in the 1st post. You can get a list of just file names or the names and complete path of all the files selected like:

B4X:
For i = 0 To FS.SelectionsSize -1
    Log(FS.GetSelection(i, False))  'Names And Paths
    Log(FS.GetSelection(i, True))   'Names Only
Next

Hello Margret,

First of all thanks for the great library. It seems to be exactly what I was searching for.
I see some indications in your description that multiple files can be selected, but I can not find samples or a description of this anywhere.

If I call the object as you show it in your sample, then the dialog closes as soon as one file is clicked / selected, so the option to select multiple file seems not given...

How can I call the selector to accept multiple selections? Many thanks in advance
Chris
 

ChrisH

Member
Licensed User
Longtime User
I forgot to show this in the 1st post. You can get a list of just file names or the names and complete path of all the files selected like:

B4X:
For i = 0 To FS.SelectionsSize -1
    Log(FS.GetSelection(i, False))  'Names And Paths
    Log(FS.GetSelection(i, True))   'Names Only
Next

Hello Margret. I have not figured out how to select multiple files with this component but if you are talking about a list of files; then I guess it is possible? I found unfortunately no sample or documentation about this, if I use the component and select one file then the dialogue immediately closes. Coud you please point me into the roght connection? Many thanks
 

ChrisH

Member
Licensed User
Longtime User
Hello, is it possible to select multiple files? The descriptions indicates that it is (Margret talks about "list of files"), but I found no code sample nor a documentation for this feature..... If yI show the dialog and click on one item then it immediately closes and does not let me select multiple items. Many thanks in advance for a short feedback!
 

Dieter Baumgartner

Member
Licensed User
Longtime User
Thank you Margret :)
I am just strugggeling, why it takes so long initializing, even if i use full- screen.
Is there a way to speed up the initialization ?
 

u2005k

Member
Licensed User
Longtime User
Hi Margret,

I am trying to use FS library... looks great. I want to select files only from list "\Files" folder, i.e I want to distribute bunch of files along with my app and I want user can select only files inside app "/Files" folder. When I use FS.ShowFiles("/Files"), I get run time error that "/Files" is not a folder.

Please let me know how it can be done.
 

u2005k

Member
Licensed User
Longtime User
Hi Margret,

I am trying to use FS library... looks great. I want to select files only from list "\Files" folder, i.e I want to distribute bunch of files along with my app and I want user can select only files inside app "/Files" folder. When I use FS.ShowFiles("/Files"), I get run time error that "/Files" is not a folder.

Please let me know how it can be done.

Hi,

Please ignore... I got it.. by using fs.ShowFiles(File.DirAssets )

Thanks a lot.
 

u2005k

Member
Licensed User
Longtime User
Hi,

Just one more thing, how can I filter only specific extension files? i.e. If I want to show only files say .jpg in the FileSelection dialog.

Thanks & regards...
 

Bpick

Member
Licensed User
Longtime User
Margaret,

I have two questions:
1) How can I start the sub in the /Pictures directory; and
2) Can you explain the syntax: FS.Initialize(Activity, Me, True, 0dip, 0dip, 500dip, 600dip)

Thank you.
 

Bpick

Member
Licensed User
Longtime User
Yes, once you select a file, the window will close unless you call the window again.
Once I select a file, how can I call it later in the program.

It's like the file is lost once I leave the sub routine
 
Top