Save files into selected directory (javascript) - javascript

Hello! My question is about javascript.
I want to
1. ask a user to select a directory
2. then write my bunch of files to it (probably with creating sub-directories) without interaction with user
How can I do this? And can I?
I am new in javascript and I hope for your help.
PS.
I've heard about ability to ask a user to select a path by save file dialog and then save data to selected file, but i want to ask a user once for selecting a directory and then create a bunch of files in it without bothering a user for each one.

Javascript alone doesn't have any way to access the local computer's file system for WRITE purposes. Period.
However, Downloadify, by Doug Neiner, was built for this purpose and uses a combination of Javascript and the Flash library.
It needs Flash 10 to work.
Alternately, you can install apache onto the computer (or better yet, a full stack like XAMPP or WAMP/MAMP/LAMP) and use PHP (with javascript/ajax) to write files onto the local file system. However, this means that the website must also be hosted locally. Probably your best bet is Downloadify
Resources:
https://github.com/dcneiner/Downloadify
How to create xml file with jquery
Save content using Jquery? Write to file
Saving to server-side file using AJAX

Related

Save CSV file as a physical file on client machine using Vanilla JavaScript [duplicate]

I have a web application that receives a simple text file, but I need this file to be downloaded to a specific path. Meaning, when the application receives a text file, it will always be downloaded to a specific folder (for example, to C:\MyFolder). If it isn't possible, then I need to copy the file from where user has chosen to my folder.
This application is based on JavaScript.
JavaScript cannot exert any control over my (the visitor's) local filesystem. I remain in complete control of where my downloaded files go, what they are named, and indeed whether I even want to download them in the first place.
Sorry, but the best you can do is inform your users where to put the file you're offering for download. You cannot use JavaScript to choose the destination yourself.
You should be able to do this using a Java applet assuming that you have signed it. The user would be asked to allow your code to run and if allowed, you could do whatever you want: Including downloading a file to a specific location.

Would like to write a javascript that helps me to find documents in a folder

I would like to write a js for an offline website (located on a local Windows server or any other server). It's supposed to look for files like PDFs in several directories and display them as search result on the "website", which isn't a real website, since it's on a local server and not in the web. The PDF is supposed to open in the browser after clicking it. I already have this kind of search engine as a php file, which I wrote with some help from friends. I also want to share this site with other friends. Basically I'll send them the whole folder with the html - document (or the .php site), so they can use it to search for certain pdfs in the folder. Its like a offline wiki for medical research documents. But I don't want them to always install php on their local servers, so they can run my php-searchmachine, thus I need to write it new as a javascript. By google and stack overflow I came across this solution https://www.codegrepper.com/code-examples/javascript/find+file+in+directory+javascript but it seems like that this needs node.js, so all have to install node.js, which is similar to installing php, I guess (im not familiar with node.js). Also I'm not sure if node.js is running on a normal client or server, which is not a webserver.
How can I start with such a project? Is javascript the correct attempt to solve this?
Windows Search has the ability to search PDF contents when boosted by a PDF (index) iFilter, this means the user can search and find instantly a new search word or a saved search it took only a second to hand enter this search (actually took longer to save for double click next time) just for illustration I chose a word I knew was in one file and actually found it is also in two other PDFs.
The problem for your JS coding is how to use JavaScript to interface with Windows Search since using explorer I could not run that search on a remote server shared library drive (I could see their contents as per second screen but for search, had to pull a local library copy down to my documents) and that is where your JS skills come into play. Personally I would avoid JS and use a VLC method to share view via a remote Lan server or simpler invoke a plain text indexed local copy of remote files for download as and when required.

Using javascript with a local html file to delete itself?

I coded a local html file that kind of works like windows notepad would, using localStorage with JavaScript to auto save. To make new notes, I have just been saving the open file as another .html file and naming it something new for the note. But I have found this to be really annoying, because when I want to delete the note, I have to actually go into my Files app, find the .html file for the note, and delete it.
I know how to use event listeners and whatever, but is there a line of code I can use to delete the file or even just ask the user for confirmation to delete the file? I basically need a way for a local html file to be able to delete itself using JavaScript. Everything I have managed to find online says that you need Node.js and it has to be on a server, but I wanted to ask anyway, because I wonder if permissions are different when the file is stored locally and not on a server.
No.
You can't use browser JavaScript to manipulate the real local filesystem. (You could access a sandboxed one, but not the real filesystem.)

Save canvas to an image file dynamically

Is there a way to download a canvas image to a file folder without a prompt showing up? I have found solutions requiring a prompt where you name the file, but I have not found any solutions where you can dynamically name the image and save to a local file. I am very new to front-end development, so I am not entirely familiar with Node.js or JQuery/PHP/Ajax. I have found solutions using these but they have ended up still using prompts.
In general, this is a security feature.
You don't want a site you browsing to save files to your computer silently. They can possibly contain a malicious code for example, or override an existing file. Thus, as a security feature the browsers are asking you to name the file you will save.
There is a way to name the files thou, so you don't need to present the user with generic file name.
On How to do that - it really depends what are you using to do it..
In your situation - if those are log files you want to save - you can send them back to the server. That can be easily done.

Open a save file dialog for a js variable

In my web app I need to give the user the option to save a js variable as a file (when the user clicks download, the app offers him to save a file, preffereably as .js file).
Similarly as google docs offers you to save a file.
Is it possible for javascript to pass it's variable this way?
Check out Downloadify which allows exactly this.
Downloadify is a tiny JavaScript + Flash library that enables the generation and saving of files on the fly, in the browser, without server interaction.
it requires Flash installed in the user's browser to work, though.
I know of no other way of doing this without server interaction.
You might also want to check out OpenSave:
http://www.gieson.com/Library/projects/utilities/opensave/
... which looks much like Downloadify, but seems to have a few extra features (and not as complicated?).

Categories

Resources