directory function

Just starting out? Need help? Post your questions and find answers here.
RobertRioja
Posts: 34
Joined: Tue Jul 16, 2019 2:07 am
Location: USA
Contact:

directory function

Post by RobertRioja »

Is there a way to scan a directory and get a list of the files in it?

Thanks,
Robert
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: directory function

Post by Peter »

RobertRioja wrote:Is there a way to scan a directory and get a list of the files in it?
No. That's not possible for security reasons.

Greetings ... Peter
RobertRioja
Posts: 34
Joined: Tue Jul 16, 2019 2:07 am
Location: USA
Contact:

Re: directory function

Post by RobertRioja »

It seems that every time I try to do anything with SP, I am told that it cannot be done for security reasons. So we can write very secure but marginally useful programs.

Thanks,
Robert
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: directory function

Post by Peter »

RobertRioja wrote:It seems that every time I try to do anything with SP, I am told that it cannot be done for security reasons. So we can write very secure but marginally useful programs.
well, you surely wouldn't like it if everyone could search your hard drive from the browser. ;)
RobertRioja
Posts: 34
Joined: Tue Jul 16, 2019 2:07 am
Location: USA
Contact:

Re: directory function

Post by RobertRioja »

I don't understand the logic. It's my program, my directory, my files, and I'm trying to write a program that is useful to me. How could anyone else have access to anything? I want to write a program that searches for files on my server. No one else is involved.

I am giving up on SpiderBasic. What I want to do can easily be done with a million tools that are already readily available (HTML, CSS, PHP, AJAX, etc, etc)

Robert
User avatar
Peter
Posts: 1086
Joined: Mon Feb 24, 2014 10:17 pm
Location: 127.0.0.1:9080
Contact:

Re: directory function

Post by Peter »

RobertRioja wrote:It's my program, my directory, my files
but you run your SpiderBasic-Application in a Browser. And the Browser must not access the file system. And even if it were possible, then you would only access the filesystem of your computer (client) and not the filesystem of the server.

To search for files on your server, you need a component that runs on your server (e.g. PHP, ASP or CGI (PureBasic))

Then you can call the server component from SpiderBasic with HTTPRequest(), which then returns the file list to SpiderBasic.
RobertRioja wrote:What I want to do can easily be done with a million tools that are already readily available (HTML, CSS, PHP, AJAX, etc, etc)
Good luck with that!

Greetings ... Peter
RobertRioja
Posts: 34
Joined: Tue Jul 16, 2019 2:07 am
Location: USA
Contact:

Re: directory function

Post by RobertRioja »

Here is the answer to my question.

This is the SpiderBasic code:

Code: Select all

Procedure WindowCloseEvent()
  CloseWindow(EventWindow()) ; Close the specific window
EndProcedure

Procedure HttpGetEvent(Success, Result$, UserData)
  If Success
    Debug Result$
  Else
    Debug "HTTPRequest(): Error"
  EndIf
EndProcedure

; Open a window and bind the events.
OpenWindow(0, 10, 10, 400, 400, "Main Window", #PB_Window_Background)
BindEvent(#PB_Event_CloseWindow, @WindowCloseEvent())

HTTPRequest(#PB_HTTP_Post, "Files.php", "?&folder=MyFolder", @HttpGetEvent())
In the HTTPRequest line, replace MyFolder with the name of the folder you are interested in.

And here is the PHP code:

Code: Select all

<?php

// Get the folder name that was passed by SpiderBasic.
  $folder = isset($_POST['folder']) ? $_POST['folder'] : '';

// Make an array with all files in the folder.
  $files = scandir($folder);

// Return all file names in a string, separated by colons.
  for ($i = 0; $i < count($files) - 1; $i++) {
    echo $files[$i] . ":";
  }
  echo $files[$i];

?>
Now use the "Create App..." menu item and create an HTML file from the SpiderBasic code. Make sure you enable the debugger. You can call it "index.html", or something suitable. Then upload it as well as the PHP file (call it "Files.php") to your web site. You also have to upload "spiderbasic.js" and the folder "spiderbasic", both of which are created by SpiderBasic.

When you visit your web site, you will see a blank screen with the debugger window open. Then you will see in it a single string with all of the files in your folder separated by colons.

The manual is missing an explanation of the relationship between SpiderBasic and the rest of the internet world (PHP, etc.). Also, I discovered by accident that "spiderbasic.js" and the folder "spiderbasic" are always needed. I also discovered that "spiderbasic.js" is recreated every time you recompile your program. I have not found any of this in the documentation.

Thank you,
Robert
plouf
Posts: 194
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: directory function

Post by plouf »

you are comparing DIFFERENT thinks
SpiderBasic is Client based (actualy spiderbasic is just translated to JavaScript)
PHP is Server based i.e.

the Purpose of SpiderBasic is to create easy WEBBASED applications, as you may have already guessed NO webbased application have access to your harddrive, eg. Gmail Client (the "think" you see inside your browser) can NOT access anythink you have either "download a file" or "upload" no other way)
however Gmail Clinet it HAS access to server located somewhere elese than your home. This server HAS a PHP (and other's) servber running ON them thus giving him access to server's Harddisk
Google "Client based vs Server Based" application's for more details

the "limitations" you are facing is the same EVERYthink that run inside a browser has (i.e any javascript webbased application/webpage)
you CANT do anything that Javascipt is not allowed to do !

IF you are searching for Executables with access to harddisk etc that run LOCALY in a computer (just like the PHP server you tun)
and a similar way of programming to SpiderBasic, Try PureBasic.
Purebasic create .exe's thus they can have acces to harddrives etc
Christos
RobertRioja
Posts: 34
Joined: Tue Jul 16, 2019 2:07 am
Location: USA
Contact:

Re: directory function

Post by RobertRioja »

Yes, I agree with everything you said. But all of this should have been in the manual. In fact, it belongs in the "Introduction" which is the very first section of the manual !!!

There should also be better explanations (and examples) of the interaction between SpiderBasic and other things like PHP.

I purchased PureBasic some time ago and use it often. It can create CGI executables but again, the manual is minimal at best. And since most servers are Linux based, you must run the Linux version of PureBasic to create a Linux executable CGI.

I have spent many decades as a software/hardware engineer and engineering manager. And I have spent many, many years as a technical writer producing user manuals, product specs, software requirements, service manuals, etc. I would be happy to help with the PB and SB manuals if I am needed. The English grammar in all of this documentation needs a lot of improvement.

But all-in-all, I am very impressed with everything that has already been accomplished. Both PB and SB are very good products, and my criticism is only meant to help improve it all.

Thank you,
Robert
bbanelli
Posts: 107
Joined: Mon Jul 13, 2015 7:40 am

Re: directory function

Post by bbanelli »

RobertRioja wrote:There should also be better explanations (and examples) of the interaction between SpiderBasic and other things like PHP.
Perhaps. On the other hand, this is a programming language, not a cup of hot McDonald's coffee. Thus, some prerequisites are expected from the user, such as basic knowledge of concepts and possibilities of stuff you use.
I purchased PureBasic some time ago and use it often. It can create CGI executables but again, the manual is minimal at best.
Well, CGI is "minimal" per se, so no issues there.
And since most servers are Linux based, you must run the Linux version of PureBasic to create a Linux executable CGI.
Once again, what is the problem? Purebasic has no crosscompiler abilities. It is nowhere stated that it has. Thus, it obviously hasn't. Super simple stuff, frankly. In addition, if you write "purebasic crosscompiler" and hit "I'm feeling lucky" in Google, you will get that very same information.
I have spent many decades as a software/hardware engineer and engineering manager. And I have spent many, many years as a technical writer producing user manuals, product specs, software requirements, service manuals, etc.
So what, you have spent many many years writing what your products can't do, rather than what they can? :D

Generally, I do agree with you that Spiderbasic's manual is far from Purebasic's one. On the other hand, Spider is much more complex than PB, to be frank. If you lack moderate knowledge of JavaScript, Spiderbasic is far from useful or understandable.

So, it is not Spider's faulty (true!) manual that prevented you from accessing your "directory function", but rather your complete lack of understanding how stuff work (plouf and Peter explained that before).

And I will repeat myself again - reading HTTP section of SpiderBasic's manual is... well.. you are right... :D

OTOH, take a look at this: https://blogs.sap.com/2016/02/10/spider ... on-server/ If you go through his code, you will see that this guy pushed SB to the "limits", using only it's bare GUI essentials, using everything else with "pure" JS.
"If you lie to the compiler, it will get its revenge."
Henry Spencer
http://www.pci-z.com/
Post Reply