0

I'm new here, so hello everyone!

I wrote a few things in Processing language and now I need to switch to Processing.js. I need to write an app that first scans the sketch folder to prepare a list of provided files. And what was straightforward in Processing is not in PJS.

I'm currently searching the web but I only found solutions for classic Processing. I know that JavaScript has restrictions and in general can't access the user-side files, but is there any way to list the sketch-itself files?

The only way that comes to my mind is to list them on server side via PHP and generate the .pde file dynamically depending on the sketch folder. But the catch is to not use any other language.

Thanks in advance for help!

Paweł Tokarz
  • 326
  • 2
  • 15

1 Answers1

0

Processing.js running on a website can only get information that URLs can provide it, and since there are no "dir listings" on the web, it can't grab dir listing content for a URL for you work with. However, depending on what you really want to do, there might be a way to make it work without resorting to PHP.

Assuming you have your Pjs page running on www.example.org/index.html, and you want to list content for www.example.org/sketch/, one option is to simply have a file www.example.org/sketch/list.txt containing all the filenames that the sketch can access, and simply grab that with a

String[] fileNames = loadStrings("./sketch/list.txt")

instruction.

If you can give an example of what you mean with "I need to write an app that first scans the sketch folder to prepare a list of provided files", a more specific solution is probably possible (i.e., what are the files, what does the user need them for, etc)

Mike 'Pomax' Kamermans
  • 49,297
  • 16
  • 112
  • 153
  • Thank you for the response. I'm writting a image gallery which I aim to work in kind of universal manner - you just put images into a specified directory and the PJS just displays the images. However for requestImage I need to provide a filename and/or path to it.For example I have file www.example.com/index.html which contains the PJS script. Images are in www.example.com/graphics/ and the PJS needs to list them and use. I want to do this dynamically - without files listed in txt file. – Paweł Tokarz Feb 05 '13 at 07:03
  • Then you probably do want a server-side script to get the dir listing. If you're running on a LAMP setup, a "listing.php" file that will do a readdir and forms a filename-per-line output, for instance will be enough to make your sketch work. The internet being as it is, however, cannot do dir listings (some server daemons will form webpages that look like a dir listing, but that's just a nice feature, not actually a standard you can rely on) – Mike 'Pomax' Kamermans Feb 05 '13 at 15:30