Using javascript to move a file on a server - javascript

So I have this html page. Inside of it is a bit of javascript code that talks to a flash application.
During the flash application's lifecycle, it'll save a file to a place on the server using the javascript on the html page.
How can I use javascript to take the file I just saved and move it to a different location?

You cannot. Javascript works on a client and don't have an access to the server's filesystem.
You can only trigger a script on the server that does that.

As you said you have node js installed and running on the server,it is possible for you to move a file using the nodejs filesystem api: http://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback
For this to work you would need to monitor and detect when new files are saved in a certain folder, which should be possible using: http://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener
Happy coding!

Related

copy file from one folder to another folder using javascript or jquery

I have a file path like this \\ptrisf02\group2\Engine_Follow\V2500-A5\V2500-A5_e-Archive\EV15159-02\Pictures_INC\INCOMING-LX\Oil tank.jpg in my database. I want to copy it another folder like T:\\Temp\\ when the button clicked in my jsp page. Is there any method to do this using javascript or jquery? I tried ActiveXObject but it gives me this error Automation server can't create object in IE.
There are two main issues you are going to run into with trying to use JS in any flavour:
Permissions and security.
JS is sandboxed.
The better way would be to use JS to fire an Ajax call which does the file copy/move for you using whatever server side language the web server is based on. That is provided that the web server actually has the permission to do so.

Load files/folders in client machine

I want to load all files/folder under path in client machine using jquery. Can we do that? It looks like file browser of window but I want to custom style for it.
Cant be done. Browsers cant access client machine file system.

Run HTML file via Bash? Possible?

I have a html file that when run in a browser such as Chrome and that contain javascript instructions, it sends the "emit" message to my websockets server and displays the value on that page.
Is there a way to call this same html file from a bash script as I'm wanting to insert data into a MySQL database which will ultimately call that html file to send an update to the websocket.
Hopefully that makes sense but hopefully there is a way to do it too :)
If you are only focused on rendering the HTML page (and not interacting with it via buttons or something) you may find this link helpful: Running HTML from Command Line
If you try to execute javascript instruction in your server without using a browser, I recommand you to use Node.JS with a real js script without html.
Otherwise you can try to run an html file with js instruction inside using something like phantomjs but I think is less performant than using Node correctly.
EDIT
It is Javascript yes, but I need to "Import" the socket.io.js file into the same script I have created and my browser I'm having to use doesn't support the new Javascript import methods. So I'm writing as HTML which calls the Javascript, otherwise I would use nodejs
I think you can import the socket.io lib in node application using npm.
https://www.npmjs.com/package/socket.io
The documentation says that you can use a client inside a node script too :
Socket.IO enables real-time bidirectional event-based communication. It consists in:
a Node.js server (this repository)
a Javascript client library for the browser (or a Node.js client)

Modify a local file with Javascript

I must make a local app with an interface. This app should load text files, modify them, and save them.
I made the interface with html/css/js, and the core of the app was made with js only.
Currently, I load the file with an input, but to save it, the browser makes me download it. I know this is a security measure.
This app is not going to be put online.
My question is : what can I do to replace directly the loaded file by the new one ?
Can I use my app (html/css/js) without a browser ?
Is there a browser that allows me to edit my local files directly ?
Is there any solution I can't think of ? Using another language to communicate with the js maybe ?
Thanks.
If you don't need your app to be online, with Electron you can make an executable using your existing code (you will have change how you're going to save the file using Electron APIs).
Being a program running on your system, you'll be able to save directly on the file system.
JS in the browser is not able to edit local files, because of security.
If you want to, you can use Node.js, a Desktop/Server Framework, which uses JS.

Save Javascript or Replace Javascript File in Chrome Developer Tools

Is there a way to replace a .js file in the website sources with a file on my workstation, or make a modification to a .js file and refresh the website to see the changes?
I am developing client-side JavaScript code against a SharePoint website on a server. I cannot create a local version of the website, so I need to modify the script, save the file to the server, refresh, etc. I do not have direct access to the server, and saving a file in a SP doc library or web part takes a lot of time between edits.
I can make small modifications using the dev tools while breaking on certain lines and applying snippets, but I am hoping for a better way.
Thanks!
If you have access the server that's hosting the file you should be able to replace or modify the JS file. Alternately you can use local hosting tools to test your file and then upload it to the server once you've confirmed it's working.
If you explain what you level of access to your host is we can offer better suggestions.

Categories

Resources