Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 200 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use Scripting.FileSystemObject to create file in path that doesn't already exist

#1
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.

[To see links please register here]


[To see links please register here]



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.
Reply

#2
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`][1] to help:

<!-- language: lang-js -->

var fso = new ActiveXObject("Scripting.FileSystemObject");
var path = "\\\\pathA\\pathB\\DirectoryDoesntExistButIWantItTo\\newfile.txt";
var folder = fso.GetParentFolderName(path);

if (!fso.FolderExists(folder))
{
fso.CreateFolder(folder);
}

fso.CreateTextFile(path, true);

[1]:

[To see links please register here]

Reply

#3
If you are going to run your code in TestComplete, you can use its own [aqFileSystem.CreateFolder][1] and [aqFile.Create][2] methods. Here is an example:

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


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through