Upload and generate a text file

Post

Posted
Rating:
#1 (In Topic #1139)
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
 Hello

I want to do the following:
1. Let the user search the disk like a file explorer. But you can only search for the txt extension.
2. Once found, Gambas should be able to use the.txt file
3. Another option is that instead of searching for it, what I want is for it to create the.txt file and it will create it from a copy that I have in the program path but with a different name. It will then copy the file.xxx and put it in the user's chosen path and rename it from file.xxx to file.txt

More or less explained, what do you suggest I do? Until now what I have done has not worked very well for me, and I always get errors or let's say the user detects errors that I cannot control.

Maybe I don't use the controls properly or I don't know.

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#2
Regular
vuott is in the usergroup ‘Regular’
...perhaps it would be appropriate for you to show those codes that generate errors: an attempt could be made to resolve them.

Europaeus sum !

<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’
Make a folder in project source dir, for example call it Templates
place your template text file in there.

Code (gambas)

  1.  
  2. Dim sTargetFile As String = User.Home &/ "new-file.txt"
  3. If not Exist(sTargetFile) Then Copy "./Templates/MyTemplate.txt" To sTargetFile
  4.  
  5.  


To search for .txt extension files just use Dir with a pattern *.txt

Code (gambas)

  1.  
  2. Dim aResults As String[]
  3.  
  4. aResults = ListTextFiles(User.Home)
  5.  
  6. Public Sub ListTextFiles(Path As String) As String[]
  7.  
  8.  Return Dir(Path, "*.txt", gb.file)
  9.  
  10.  
  11.  


To search for text/plain mimetype files use DesktopMime.class from gb.desktop

Code (gambas)

  1.  
  2. Dim aResults As String[]
  3. aResults = ListTextMimeFiles(User.Home)
  4.  
  5. Public Sub ListTextMimeFiles(Path As String) As String[]
  6.  
  7.   Dim aTextFiles As New String[]
  8.  
  9.   Dim aFiles As String[] = Dir(Path, "*", gb.File)
  10.  
  11.   For Each sFile As String In aFiles
  12.     If DesktopMime.FromFile(Path &/ sFile).Type = "text/plain" Then aTextFiles.Add(sFile)
  13.    Next
  14.  
  15.   Return aTextFiles
  16.  
  17.  
  18.  
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’

gambafeliz said

More or less explained, what do you suggest I do? Until now what I have done has not worked very well for me, and I always get errors or let's say the user detects errors that I cannot control.

Maybe I don't use the controls properly or I don't know.

Hehe , more or less lol :)

post example code of what you are having trouble with dude.  
our native tongues are different and explanations can be hard to understand sometimes.
We all speak gambas though ;)
that question would have been much easier to understand exactly what you want to do if you had posted the code too :)
Online now: No Back to the top

Post

Posted
Rating:
#5
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
 My fault. The thing is, maybe I haven't been able to explain myself and in the end I don't really know what to ask of you.

I tell you, but I don't see how to put the code.

I read a configuration file and see if the path of the .txt file is there, if it does not exist, I show a form for the user to search for it among the files or create a new one. When creating it, I only ask them to give it a name and I will do it. I create from one existing among my installation files of my program. I also save in the configuration file that this new or searched is the favorite for the user, so that it loads it by default.

I have done all this but in a rudimentary way or with a personalized form.

My question is more about: is it possible to create it with components already created in gambas?

And if not, someone will send me a similar but optimized form. The thing is that mine is currently chaotic and is not going as well as I would like. To say that I don't put it in because it refers to the configuration and routes file that is of no use to anyone. Besides, I don't want to do it because it is poorly developed.

Finally, I understand that I cannot be helped in this case.

And please I apologize for the bad question. Thank you anyway.

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’
er no i do not think there is a component for that.

You'll have to code it yourself.
it shouldn't be too hard.
That's the learning process,
I am sure you will figure out and refine an okay way to do it :)
Practice makes perfect :)
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Guru
cogier is in the usergroup ‘Guru’
1. Let the user search the disk like a file explorer. But you can only search for the txt extension.
2. Once found, Gambas should be able to use the.txt file

Try the following code. 1/. It lists all the .txt files is the Home folder and its sub folders. 2/. If you double-click on a file, it will open it in a TextArea.   

Am I going in the correct direction?

Code (gambas)

  1. GridViewList As GridView
  2. TextAreaEdit As TextArea
  3. sFiles As String[]
  4. sLang As String[]
  5.  
  6. Public Sub Form_Open()
  7.  
  8.   Setup
  9.   GetFiles
  10.  
  11.  
  12. Public Sub GetFiles()
  13.  
  14.   Dim iRow As Integer
  15.  
  16.   sFiles = RDir(User.Home, "*.txt", gb.File).Sort()
  17.  
  18.   For iRow = 0 To sFiles.Max
  19.     If sFiles[iRow] Begins "." Then Continue ''Don't show hidden files (No mostrar archivos ocultos)
  20.     Inc GridViewList.Rows.Count
  21.     GridViewList[GridViewList.Rows.Max, 0].Text = User.Home &/ sFiles[iRow]
  22.   Next
  23.  
  24.   Me.Title = sLang[0] & "(" & Str(GridViewList.Rows.Count) & ")"
  25.  
  26.  
  27. Public Sub GridViewList_Click()
  28.  
  29.   Dim iLast As Integer = Last.Row
  30.   Dim iRow, iColour As Integer
  31.   Dim bBold As Boolean
  32.  
  33.   For iRow = 0 To GridViewList.Rows.Max
  34.     iColour = Color.Default
  35.     bBold = False
  36.     If iRow = iLast Then
  37.       iColour = Color.LightGray
  38.       bBold = True
  39.     End If
  40.     GridViewList[iRow, 0].Background = iColour
  41.     GridViewList[iRow, 0].Font.Bold = bBold
  42.   Next
  43.  
  44.  
  45. Public Sub GridViewList_DblClick()
  46.  
  47.   GridViewList.Visible = False
  48.   TextAreaEdit.Visible = True
  49.  
  50.   TextAreaEdit.Text = File.Load(GridViewList[Last.Row, 0].Text)
  51.   Me.Title = GridViewList[Last.Row, 0].Text
  52.  
  53.  
  54. Public Sub Setup()
  55.  
  56.   If System.Language Begins "en" Then sLang = ["Text file list", "Double click to open"]
  57.   If System.Language Begins "es" Then sLang = ["Lista de archivos de texto", "Doble clic para abrir"]
  58.  
  59.   With Me
  60.     .Arrangement = Arrange.Vertical
  61.     .Padding = 5
  62.     .Height = 550
  63.     .Width = 850
  64.  
  65.   With GridViewList = New GridView(Me) As "GridViewList"
  66.     .Columns.Count = 1
  67.     .Rows.Count = 0
  68.     .ScrollBar = GridView.Vertical
  69.     .Grid = False
  70.     .Expand = True
  71.     .Header = GridView.Vertical
  72.     .Tooltip = sLang[1]
  73.     .Visible = True
  74.  
  75.   With TextAreaEdit = New TextArea(Me)
  76.     .Expand = True
  77.     .Wrap = True
  78.     .Visible = False
  79.  
  80.  
Online now: No Back to the top

Post

Posted
Rating:
#8
Enthusiast
gambafeliz is in the usergroup ‘Enthusiast’
 Thanks cogier

I'll look at it to see if it serves as a guide for my file opening.

For your misfortunes I am Spanish and I only know Spanish, please, be patient with me, Thank you. :)
Online now: No Back to the top

Post

Posted
Rating:
#9
Guru
BruceSteers is in the usergroup ‘Guru’

cogier said

Code (gambas)

  1.  
  2.   sFiles = RDir(User.Home, "*.txt", gb.File).Sort()
  3.  
  4.  

Wow  , after all these years of making many a recursive Dir function I have just learned there is an RDir command  :shock:  :D

Cool  8-)
Online now: No Back to the top
1 guest and 0 members have just viewed this.