19

Is there any way I can use HTML5 and JavaScript to modify a file on my system? I'm OK with running Chrome or Firefox with specific options or opening permissions in some other way.

Ideally I would like test this by having my browser rename a file on my desktop.

Kirk Ouimet
  • 27,280
  • 43
  • 127
  • 177

3 Answers3

6

Yes, you can do this, this link details some of the available functionality:

http://www.html5rocks.com/en/tutorials/file/filesystem/

Just remember, it's not supported in the major browsers yet, and it's likely when it is many of your visitors will not upgrade for quite some time.

Jeremy Morgan
  • 3,314
  • 23
  • 23
  • 4
    It looks like this only gives you access to a sandboxed filesystem – Kirk Ouimet Jun 23 '11 at 16:23
  • 1
    Here's some text from the link: It's important to remember that this file system is sandboxed, meaning one web app cannot access another app's files. This also means you cannot read/write files to an arbitrary folder on the user's hard drive (for example My Pictures, My Documents, etc.). – Kirk Ouimet Jun 23 '11 at 17:31
  • @Kirk: That's actually a Good Thing. Would you like just any ol' webpage to access your documents? Like, your personal data? I wouldn't, for one. – Piskvor left the building Aug 29 '11 at 14:56
  • 3
    @Piskvor For my particular use case I'd like it to have access to approved directories in the file system – Kirk Ouimet Sep 03 '11 at 18:41
  • Cool side note: Google Chrome is building an in browser editor. https://github.com/GoogleChrome/code-editor-app – Michael J. Calkins Sep 05 '13 at 16:32
3

No, as this would be a security vulnerability. As pointed out there are sandboxed file systems, or local database storage in HTML5, but not access to the whole file system.

You could achieve it with a certified Java applet, if you really wanted to achieve it through the browser. To be honest the browser is not the best place to be trying such things.

Tak
  • 11,428
  • 5
  • 29
  • 48
  • 1
    Java applets are no longer supported, so I would use the [File System Access API](https://web.dev/file-system-access/) to modify local files instead. – Anderson Green Feb 15 '22 at 22:36
-1

VBScript should be appropriate in your case. You will have to lower your internet zone security level though.
Once it's done just use ActiveXObject("Scripting.FileSystemObject") and its MoveFile method.

Knu
  • 14,806
  • 5
  • 56
  • 89