使用 WScript.shell 写入文件

发布于 2024-12-20 09:16:20 字数 452 浏览 4 评论 0原文

如何使用 WScript 编写文本文件 我对此非常陌生,这就是为什么我无法提供一些详细信息。我想编写一个可以存储在 c://users/user/appdata/local 中的日志文件

我的示例代码,使用 FileSystemObject

function WriteFile() 
{
   var fso  = new ActiveXObject("Scripting.FileSystemObject"); 
   var fh = fso.CreateTextFile("d:\\Test.txt", true); 
   fh.WriteLine("Some text goes here..."); 
   fh.Close(); 
}

<body onload = "WriteFile();">
</body>

它确实返回在 d: 中,但在本地 c: 中则不会。

How can I write text files using WScript I'm really new on this that's why I cannot give some details. I want to write a log file that can be stored in c://users/user/appdata/local

my sample code, using FileSystemObject

function WriteFile() 
{
   var fso  = new ActiveXObject("Scripting.FileSystemObject"); 
   var fh = fso.CreateTextFile("d:\\Test.txt", true); 
   fh.WriteLine("Some text goes here..."); 
   fh.Close(); 
}

<body onload = "WriteFile();">
</body>

it does return in d: but in local c: it wont.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七色彩虹 2024-12-27 09:16:20

您在 fh 中缺少一个重要参数。正确的代码是:

var fh = fso.CreateTextFile("d:\\Test.txt", 2, true);

2 是字节码,它告诉 fso 写入文件。对于读取值是 1,对于附加值是 8。

我想现在您已经清楚了。

You are missing one important parameter in fh. The right code is:

var fh = fso.CreateTextFile("d:\\Test.txt", 2, true);

whereas 2 is a bytecode, which tells to fso to write a file. For reading value is 1, and for appending value is 8.

This is clear to you by now, I suppose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文