JavaScript - 提取文件夹名称
我对 JavaScript 还很陌生。
给定本地计算机的文件夹路径(Windows),我想知道如何提取当前路径中所有可能文件夹的名称,而不知道有多少个文件夹或它们的名称。
预先非常感谢您。
I'm fairly new to JavaScript.
Given a local machine's folder path (Windows), I was wondering how you can extract the names of all the possible folders in the current path, without the knowledge of how many folders there are or what they are called.
Thank you very much in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您在 Web 浏览器中执行 JavaScript,则不能,因为在这种情况下,出于安全原因,JavaScript 无法访问本地文件系统。
If you're executing JavaScript in a web browser then you can't, because in this scenario JavaScript has no access to the local file system for security reasons.
下面是一个小脚本,可帮助您开始将 FileSystemObject 与 JScript 结合使用:
在命令行上使用 csript.exe 调用该
脚本: Windows 脚本 5.6 文档 包含您需要的有关此主题(以及许多其他主题)的所有详细信息。 下载它并随身携带,它真的很有帮助。 在 Windows 系统上,稍微了解一下 FileSystemObject 及其亲属确实可以挽救局面。
Here is a little script to get you started with FileSystemObject in conjuction with JScript:
Call that with csript.exe on the command line:
The Windows Script 5.6 Documentation holds all the details you need on this topic (and many others). Download it and have it around, it is really helpful. On Windows systems, a little knowledge of FileSystemObject and it's relatives really can save the day.
您无法通过浏览器中的 Javascript 执行此操作,因为 JS 无法从浏览器访问文件系统。
You cannot do this via Javascript in a browser as the JS doesn't have that kind of access to the file system from a browser.
假设脚本将在尝试访问本地硬盘驱动器(例如在 cscript 或经典 ASP 中)有意义的上下文中执行,那么最好的选择是 FileSystemObject。
Assuming the script will execute in a context where it makes sense to try and access the local hard drives (e.g. in cscript or classic ASP), your best bet is the FileSystemObject.