使用Scripting.FileSystemObject在尚不存在的路径中创建文件 [英] Use Scripting.FileSystemObject to create file in path that doesn't already exist

查看:144
本文介绍了使用Scripting.FileSystemObject在尚不存在的路径中创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用JScript中的Scripting.FileSystemObject创建文本文件.如果文件中的目录尚不存在,我似乎无法弄清楚如何创建文件.例如:

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);

我一直在寻找,但似乎有关此文档的内容并没有整齐地放在一个地方.例如,这里有一些MSDN文章,它们在讨论这一点,但忽略了我正在寻找的详细信息.

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

换句话说,我正在努力向Google努力,但没有找到我想要的东西.我认为这没有什么不同;但我正在TestComplete 8中编写此脚本;但出于所有深入的目的,您可以假定我正在IE上html文件中的脚本标记中运行它.

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.

推荐答案

如果要在TestComplete中运行代码,则可以使用其自己的 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:

createFile("\\\\pathA\\pathB\\DirectoryDoesntExistButIWantItTo\\newfile.txt");
...
function createFile(fileName)
{
  aqFileSystem.CreateFolder(aqFileSystem.GetFileFolder(fileName));
  aqFile.Create(fileName);
}

这篇关于使用Scripting.FileSystemObject在尚不存在的路径中创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆