This seems like it should be easy. I've never used JScript before and I'm looking at the JScript api provided by microsoft but no luck. Here's what I have:
var fso, tf;
fso = new ActiveXObject("Scripting.FileSystemObject");
tf = fso.CreateTextFile("New Tracks.txt", true);
var objShell = new ActiveXObject("Shell.Application");
var lib;
lib = objShell.BrowseForFolder(0,"Select Library Folder",0);
items = lib.Items()
for (i=0;i<items.Count;i++)
{
fitem = items[i];
tf.WriteLine(fitem.Name);
}
WScript.Echo("Done");
tf.Close();
I get an error about fitem.Name that it's not an object or null or something. However, there are definitely files in that folder.
This seems like it should be easy. I've never used JScript before and I'm looking at the JScript api provided by microsoft but no luck. Here's what I have:
var fso, tf;
fso = new ActiveXObject("Scripting.FileSystemObject");
tf = fso.CreateTextFile("New Tracks.txt", true);
var objShell = new ActiveXObject("Shell.Application");
var lib;
lib = objShell.BrowseForFolder(0,"Select Library Folder",0);
items = lib.Items()
for (i=0;i<items.Count;i++)
{
fitem = items[i];
tf.WriteLine(fitem.Name);
}
WScript.Echo("Done");
tf.Close();
I get an error about fitem.Name that it's not an object or null or something. However, there are definitely files in that folder.
Share Improve this question edited Apr 19, 2011 at 19:43 JPC asked Apr 19, 2011 at 18:44 JPCJPC 8,29622 gold badges78 silver badges110 bronze badges 1- Perhaps there is another way, what are you trying to do? – James Allen Commented Apr 19, 2011 at 18:58
3 Answers
Reset to default 3The items
variable in your script holds a FolderItems
collection rather than an array. To access the collection's items, you need to use the Items(index)
notation. So, replacing
fitem = items[i];
with
fitem = items.Item(i);
will make the script work.
This works for me, I had to change the path to the file or I get access denied (win 7).
<script language="JScript">
var fso, tf;
fso = new ActiveXObject("Scripting.FileSystemObject");
tf = fso.CreateTextFile("c:\\New Tracks.txt", true);
var objShell = new ActiveXObject("Shell.Application");
var lib;
lib = objShell.BrowseForFolder(0,"Select Library Folder",0);
var en = new Enumerator(lib.Items());
for (;!en.atEnd(); en.moveNext()) {
tf.WriteLine(en.item());
}
WScript.Echo("Done");
tf.Close();
</script>
Apparently you can't access it like an array and have to call the Item() method.