最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

activex - rename a file in javascript - Stack Overflow

programmeradmin2浏览0评论

i want to ask that if i want to rename a file in javascript, what can i do ? i have try a function which i see it online but cannot work.

function ChangeFileName()
{
    var fso, f;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    f = fso.GetFile("FilePath/MyFile.txt");
    f.name = "MyFile.htm";
} 

i search online and it says that the ActiveXObject is only available for IE and i intended to use it on mozilla because mozilla es with ubuntu.

beside this, is there any method that i can rename a file inside the javascript ? thanks in advance for your help .

i want to ask that if i want to rename a file in javascript, what can i do ? i have try a function which i see it online but cannot work.

function ChangeFileName()
{
    var fso, f;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    f = fso.GetFile("FilePath/MyFile.txt");
    f.name = "MyFile.htm";
} 

i search online and it says that the ActiveXObject is only available for IE and i intended to use it on mozilla because mozilla es with ubuntu.

beside this, is there any method that i can rename a file inside the javascript ? thanks in advance for your help .

Share Improve this question edited May 16, 2012 at 12:47 Bakudan 19.5k9 gold badges55 silver badges75 bronze badges asked May 16, 2012 at 12:44 EricEric 3994 gold badges13 silver badges21 bronze badges 2
  • the file you want changed, is on the client (user with browser) or on the server (servicing web server)? – ericosg Commented May 16, 2012 at 12:47
  • I don't think you can. Javascript in browsers really isn't meant to deal with the local operating system, and certainly not in a cross-platform manner. – Jason S Commented May 16, 2012 at 12:48
Add a ment  | 

3 Answers 3

Reset to default 2

It is Javascript (in the browser), right?

If you run in the browser it is not allowed for security reasons. I think there is some way to do this using IE and ActiveX but using Pure Javascript I think it is not possible.

But you can do in JScript in the console, for example to delete a single file:

function MoveFile2Desktop(filespec)
{
   var fso;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   fso.MoveFile(filespec, "newname");
}

No, you cannot rename a file with javascript. Javascript is not able to interact with the user's puter in any way - it is only intended to be used to interact with the content of the web page it is rendered on.

JavaScript has no built in means to interact with a file system.

A host object might provide such a means.

The host object (window) that is available to JavaScript loaded from a web page in a typical web browser exposes no such object. Web pages are not allowed to edit the disks of people visiting their sites. (The exception is IE, with ActiveX, and some security warnings).

If you were running JavaScript in a browser extension or in a different environment (such as node.js) then it might be possible.

发布评论

评论列表(0)

  1. 暂无评论