使用 Scripting.FileSystemObject 在尚不存在的路径中创建文件
我正在尝试使用 JScript 中的 Scripting.FileSystemObject 创建一个文本文件。如果文件中的目录尚不存在,我似乎无法弄清楚如何创建该文件。例如:
var fso = new ActiveXObject("Scripting.FileSystemObject");
// Getting a JScript runtime error of "Path not found"
fso.CreateTextFile("\\\\pathA\\pathB\\DirectoryDoesntExistButIWantItTo\\newfile.txt", true);
我一直在到处寻找,但似乎有关此的文档并没有整齐地放在一个地方。例如,这里有一些 MSDN 文章讨论了这一点,但省略了我正在寻找的细节。
http://msdn.microsoft.com/en- us/library/aa711216(v=VS.71).aspx
http://msdn.microsoft.com/en-us/ library/aa242706(v=VS.60).aspx
换句话说,我正在尽力用 Google 搜索此内容,但没有找到我要找的内容。我认为这没有什么区别;但我正在 TestComplete 8 中编写这个脚本;但对于所有密集的目的,您可以假设我在 IE 上的 html 文件内的脚本标记中运行它。
I'm trying to create a text file using the Scripting.FileSystemObject in JScript. I can't seem to figure out how to create the file if a directory in the file doesn't already exist. For example:
var fso = new ActiveXObject("Scripting.FileSystemObject");
// Getting a JScript runtime error of "Path not found"
fso.CreateTextFile("\\\\pathA\\pathB\\DirectoryDoesntExistButIWantItTo\\newfile.txt", true);
I've been looking all over but it seems like the documentation on this isn't neatly put in one place. For example, here are some MSDN articles which talk about this but leave out the details I'm looking for.
http://msdn.microsoft.com/en-us/library/aa711216(v=VS.71).aspx
http://msdn.microsoft.com/en-us/library/aa242706(v=VS.60).aspx
In other words, I'm trying my best to Google this and I'm not finding what I'm looking for. I don't think this makes a difference; but I'm writing this script within TestComplete 8; but for all intensive purposes you can assume I'm running it in a script tag within an html file on IE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为如果该文件夹不存在,您需要手动创建该文件夹。如果您只需要担心直接父文件夹,可以使用
GetParentFolderName
来帮助:I think that you need to manually create the folder if it doesn't exist. If you only need to worry about the immediate parent folder, you can use
GetParentFolderName
to help:如果您要在 TestComplete 中运行代码,则可以使用其自己的 aqFileSystem.CreateFolder 和aqFile.Create 方法。这是一个例子:
If you are going to run your code in TestComplete, you can use its own aqFileSystem.CreateFolder and aqFile.Create methods. Here is an example: