How to know file names into a directory with processing.js or p5.js?

Hello everyone.

I'm working on a simple project with an industrial controller.
It uses some physical sensors to measure some physical values (voltage, current, etc.) and creates a log file (.csv) every hour, keeping the older files into its memory. Then I can go via ftp:// into its memory and get those files.

What I would like to do is to put a web page on it, and show a plot of the csv recorded values.
I tried both using processing.js and p5.js, and, if I know the name of the file, it works (I've never made a web page before! :) ).

But, if I don't know the files names, I don't know how to open a file whose name is unknown (obviously).

Any idea how to know files names into a folder?
(the web page is in the same directory of the csv files, so I don't need to use absolute url path).
What I usually use with "standard" Processing doesn't work in this situation.
I just need to have a String variable that contains the name of the unknown file (or an array, if many files).

The file have this format: controller-name_YYYY_MM_DD_hh_mm.csv (and I can't change this :( )

Thanks to everyone


    • AFAIK, a browser program (frontend) can't get the list of files within a directory. :(
    • You're gonna need a server program for it. L-)
    • However, my backend knowledge is almost nil. X_X
    • Processing (Java Mode) is based on Java. And we can write servers in Java. Just look up for it.
  • thanks for your answer :)

    but I think there could be some "trick", to let me find out those file names.

    I've already tried two ways:
    1. I've put a button, that pressed, let me select a file. It works locally on my PC, but when I put the web page on the ftp server it doesn't work anymore.
    2. I've used exceptions: I try to load a file using a String variable that changes thanks to a cycle. For example, I try to load files from controller-name_YYYY_MM_DD_hh__00.csv to controller-name_YYYY_MM_DD_hh__59.csv. If one of these 60 file exists, I show the plot. Again, It works locally on my PC, but when I put the web page on the ftp server it doesn't work anymore.

    What do you mean with "we can write servers in Java"?
    I can't install anything on the server, it's an industrial controller, a PLC, not a PC :(

    Any suggestion?

  • Sorry. I dunno the effects of an FTP server.
    What I meant by a server in Java is having a program that creates and serves an HTML file.
    The server has access to any file. While scripts run in a browser can't scan for files.
    But as I've mentioned before, that's as far as I know about the subject. ~:>

  • What OS runs on the PLC? The unit is the the server so people connect to it, is that right? Can you provide the model and mark of the unit?


  • edited December 2016

    The device is an industrial controller (not common CPU, OS, etc.)
    A program is running, and at the same time, it works as ftp server, and let you browse into its memory.
    I can put any kind of file inside the memory/ftp server.
    But nothing can be executed or installed on it.
    It's a memory storage that can be reached via ftp. Nothing else.
    This is why I have to use javascript, 'cause in this way, what I get from the web page is list of commands that the client have to execute. Any client. But not the server.
    In fact, it works when, using loadStrings, I put as argument a String variable who contains the name of the file that I want to load.
    But, is there an FTP library (or something else) that let me know which files are contained in a folder of an fpt server?

    Any trick? [-O<

  • @ecce_robot

    I think there could be some "trick", to let me find out those file names.

    There are a lot of StackOverflow answers that say "you can't do this."

    However, if you are looking for a client-side javascript library that speaks FTP and that is the only solution you can use, perhaps this will work? Untested.

    As an alternative approach I would suggest that you create a separate sync job (e.g. a cron job) that periodically (hourly) syncs the complete contents of the ftp server to a directory on the same webserver as your p5.js script. Then load your directory listing in Javascript as normal.

  • thank you so much for your help but (if I understood correctly) this library is for NodeJS.
    So it doesn't work in my situation.
    I'll update this discussion when i'll find a solution.

    Thanks a lot again!

Sign In or Register to comment.