在 VBScript 中枚举区分大小写的文件?
我使用以下 VBScript 代码片段来枚举 c:\Scripts\ 文件夹中的所有文件:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
ExecQuery("Select * from CIM_DataFile where Path = '\\Scripts\\'")
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
不幸的是 objFile.Name 返回全部小写的路径。 对我来说,检索所有文件名的大小写很重要,即 NewFileOne.txt,不应作为 newfileone.txt 返回。
有没有办法在 VBScript 中枚举区分大小写的文件?
I am using the following VBScript code snippet to enumerate all files in my c:\Scripts\ folder:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService. _
ExecQuery("Select * from CIM_DataFile where Path = '\\Scripts\\'")
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
Unfortunately objFile.Name returns the path in all lower-case. It is important to me to retrieve the case of all file names, i.e. NewFileOne.txt, should not be returned as newfileone.txt.
Is there a way to enumerate files with case-sensitivity in VBScript?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您使用 FileSystemObject,您将返回保留大小写的名称
文件集合 (MSDN)
If you use the FileSystemObject, you will get back names with the case preserved
Files Collection (MSDN)
与
CIM_DataFile.Name
属性不同,FileName
和Extension
属性区分大小写。 因此,如果您需要使用WMI,您可以分别检索文件名和扩展名:Unlike the
CIM_DataFile.Name
property, theFileName
andExtension
properties are case sensitive. So, if it's necessary for you to use WMI, you can retrieve the file name and extension separately:迈克的解决方案更好,但这里有一个非常丑陋的替代方案:
使用 shell exec 执行以下命令:
现在“file.txt”包含以正确大小写列出的文件。
抱歉,它很难看,但有效。
Mike's solution is better, but here's A VERY UGLY alternative:
Using the shell exec execute the following command:
Now "file.txt" contains the file listed with proper casing.
Sorry, it's ugly but works.