Page 1 of 1

Equivalent to Fileexist in SB

Posted: Thu Aug 05, 2021 4:04 pm
by loulou2522
Is it possible to test if a file exist like in purebasic ?
Is it possible to access to document folder or desktop folder or appdata local like en purebasic

THanks

Re: Equivalent to Fileexist in SB

Posted: Thu Aug 05, 2021 4:32 pm
by Peter
Although modern browsers support native file access, this is not yet possible with native SpiderBasic commands.

Re: Equivalent to Fileexist in SB

Posted: Thu Aug 05, 2021 4:53 pm
by loulou2522
and for file exist like in purebasic ?

Re: Equivalent to Fileexist in SB

Posted: Thu Aug 05, 2021 5:07 pm
by Peter
loulou2522 wrote: Thu Aug 05, 2021 4:53 pm and for file exist like in purebasic ?
same (native file access).

In general, if it is not in the SpiderBasic help, then it is not natively supported.

Re: Equivalent to Fileexist in SB

Posted: Thu Mar 09, 2023 1:14 pm
by AZJIO
I wanted to find files in data folder using Callback.
I wanted to find files that I could select from the menu to change the color of window elements. I could put 3 or 10 files in a folder and that there would be an automatic detection of the number of files and, accordingly, the same number of menu items.
I did a lot of experiments and realized that I need the g_idStyleFile(i) array, because the code in the loop does not wait until the file opens and starts the next one. Maybe the engine assumes the file is online and waits some time before getting the status of the file's status, otherwise it wouldn't have the #PB_Status_Progress status. Why does #PB_Status_Loaded allow for a non-existent file? If I loop to 20 and there are 10 files, then I get 20 files. I reworked the algorithm several times and so far I have come to the conclusion that the loop counter should be the same as the number of files, only then I get a working program. But then it's not a real file check.

Code: Select all

Global g_id_file
Global g_id_fileStyle, g_FStyle
Global Dim g_idStyleFile(7)

Procedure FileExistCallback(Status, Filename$, File, Size)
  Protected fn, fn$, Text$
  If Status = #PB_Status_Loaded
    fn$ = StringField(Filename$, 3, "/")
    fn = Val(fn$)
    If fn$ = "1"
      OpenSubMenu("Style")
    EndIf
    If ReadByte(g_idStyleFile(fn))
      Debug fn
      MenuItem(22 + fn, fn$)
      CloseFile(g_idStyleFile(fn))
      g_FStyle + 1
    Else
      ProcedureReturn
    EndIf
    If fn = 7
      CloseSubMenu()
      MenuItem(20, "About")
    EndIf
    ; 	ElseIf Status = #PB_Status_Error
    ;         ProcedureReturn
  EndIf
EndProcedure


Procedure EventsMenu()
  eMenu = EventMenu()
ElseIf eMenu > 22
  g_id_file = ReadFile(#PB_Any, "./data/" + Str(eMenu - 22), @ReadCallback())
EndIf
EndProcedure

; ———————

If CreatePopupMenu(#MenuSet)
  MenuItem(22, "qwer")
  For i = 1 To 7
    g_idStyleFile(i) = ReadFile(#PB_Any, "./data/" + Str(i), @FileExistCallback())
  Next
EndIf
BindEvent(#PB_Event_Menu, @EventsMenu())

Re: Equivalent to Fileexist in SB

Posted: Thu Mar 09, 2023 3:05 pm
by useful
You again have a problem in understanding the principles behind the security of web technology.
One or more if a multiselect key is specified.
But only what the user selects, not what is in the folder.

#PB_Requester_MultiSelection !!!

Code: Select all

  Procedure RequesterSuccess()
    While NextSelectedFile()
      Debug "Filename: " + SelectedFileName()
    Wend
  EndProcedure
   Procedure ButtonEvent()
    OpenFileRequester("", @RequesterSuccess(), #PB_Requester_MultiSelection)
  EndProcedure
  If OpenWindow(0, 100, 100, 200, 55, "File")
    ButtonGadget(0, 10, 10, 170, 25, "Open local file...")
    BindGadgetEvent(0, @ButtonEvent())
  EndIf

Re: Equivalent to Fileexist in SB

Posted: Thu Mar 09, 2023 4:08 pm
by AZJIO
The OpenFileRequester() function opens a selection dialog. My task is to make this choice independently by the program. I don't want to force the user to rummage through folders. I could add presets to the program, but then I would have to rewrite the code. I want the settings to be in separate files, then without rewriting the program, you can create your own presets. What you gave me is already built into the program. If the user wants to change the window style, he will have to search for the file in the file manager for 20 seconds, and I want him to spend 1 second without straining his brain. You can try here. Look at the screenshot. Style->2. What you gave me is done by the item "Open ini"

Re: Equivalent to Fileexist in SB

Posted: Thu Mar 09, 2023 4:22 pm
by useful
AZJIO wrote: Thu Mar 09, 2023 4:08 pm My task is to make this choice independently by the program.
It fundamentally contradicts the basics of web program security.
You need another tool. SB makes a site packaged in an app.

Re: Equivalent to Fileexist in SB

Posted: Thu Mar 09, 2023 6:30 pm
by AZJIO
What is the "data" folder for? We recently came to the decision that files can be added to the project at the compilation stage, and then opened. My task is to open several files and close them at once, making sure that the files exist in the "data" folder inside the program. Then I can add as many menu items as there are files without having to force the number of files. If this causes a problem since the program will wait 5 minutes for the file to open, then I will refuse this opportunity.

Re: Equivalent to Fileexist in SB

Posted: Fri Mar 10, 2023 6:14 am
by useful
AZJIO wrote: Thu Mar 09, 2023 6:30 pm What is the "data" folder for?
...
loadimge, loadjson, loadxml, etc.