I want to scan the files in the site’s public folder (that I import from) and get a directory. A bit like the windows code:
var
DirInfo : TSearchRec;
sFile : string;
iDosError : integer;
b
iDosError := FindFirst(‘.’,$3F,DirInfo);
while iDosError = 0 do
begin
sFile := DirInfo.Name;
do_something(DirInfo.Name);
iDosError := FindNext(DirInfo)
end
and then open it for read.
Also to write there, all using WIX javascript.
Hi,
These files are not accessible via URL (unless you upload a txt file via media manger, then it’ll get an auto-URL, but you can’t set the url).
sometimes I use
// backend/serve-files.jsw
export function readFile(filePath){
//for example, filePath = 'backend/directoryname/file.txt'
const fs = require('fs');
return fs.readFileSync(require.resolve(filePath)).toString();
}
to read the contents of a file in a known directory path.
You probably can use it in a jsw file
Just import the function to the front end and use it.
(with some adjustment you can read js files and not only txt files)
Maybe there’re simpler ways (I never needed it on the frontend, so I never tried).
Why can’t you use the code I wrote yesterday? (maybe elaborate what you’re trying to do).
Anyway, you can combine the code I posted yesterday with an http-function if that what you need.
For example, I have code snippet that my partners implement on their non-Wix website, and the src points to my Wix http function url, once I get the request, I read the file content (with the code In posted yesterday) and return it as a javascript resource.
I note that the snippet only “compiles” if it is in the backend folder, the requires would not work otherwise. Is there something special about the backend folder in that respect?
Can I also do a write to a file in the same idea? and even get a list of the files?
Thanks a lot. I did not see your code in the email notification that I got, so thanks.