Read all files in a directory

Just starting out? Need help? Post your questions and find answers here.
Stefan
Posts: 248
Joined: Mon Feb 05, 2018 9:44 pm

Read all files in a directory

Post by Stefan »

I want to read all the files in a directory.
I found this PHP code for that.

Code: Select all

<?php
foreach (glob("*.*") as $filename) {
    echo "$filename - Größe: " . filesize($filename) . "\n";
}
?>

But how do I retrieve the result in SpiderBasic?
plouf
Posts: 295
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: Read all files in a directory

Post by plouf »

php code runs in a webserver, so this code must located in webserver , you call like any other page i.e

if for example i want to execute an example.php script located in webserver
HTTPRequest(#PB_HTTP_Get, "http://www.stefan.com/example.php, "", @callbackHttpGetEvent())

callback will receive php exported data

keep in mind that it will list directory of local webserver php is running to
Christos
Stefan
Posts: 248
Joined: Mon Feb 05, 2018 9:44 pm

Re: Read all files in a directory

Post by Stefan »

That's exactly what it's about :)
I don't know how to read the data in callbackHttpGetEvent() :)
plouf
Posts: 295
Joined: Tue Feb 25, 2014 6:01 pm
Location: Athens,Greece

Re: Read all files in a directory

Post by plouf »

Http request has an example ,

Code: Select all


      Procedure HttpGetEvent(Success, Result$, UserData)
        If Success
          Debug Result$
        Else
          Debug "HTTPRequest(): Error"
        EndIf
      EndProcedure
      
      ; Get the content of this file, and display it in the debug window
      ;
      HTTPRequest(#PB_HTTP_Get, "http://www.stefan.com/phpscript.php, "", @HttpGetEvent())

       
https://www.spiderbasic.com/documentati ... quest.html

Note that sb script MUST be in www.stefan.com url AND executed from a webbrowser
Christos
Stefan
Posts: 248
Joined: Mon Feb 05, 2018 9:44 pm

Re: Read all files in a directory

Post by Stefan »

Great!
Thank you so much! :)
Post Reply