jscript - 获取目录中的文件列表 [英] jscript - getting list of files in directory

查看:107
本文介绍了jscript - 获取目录中的文件列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这似乎应该很容易。我之前从未使用过JScript,我正在查看微软提供的JScript api,但没有运气。这就是我所拥有的:

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

我收到有关fitem.Name的错误,表示它不是对象或null或其他内容。但是,该文件夹中肯定存在文件。

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.

推荐答案

项目脚本中的变量包含 FolderItems 集合而不是数组。要访问该集合的项目,您需要使用 项目(索引) 表示法。所以,替换

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

将使脚本正常工作。

这篇关于jscript - 获取目录中的文件列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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