我有下面的代码,它从文件夹中获取 txt 文件列表,我想从返回的文件名中删除 .txt,我该如何实现这一点?
Set objFSO = CreateObject("Scripting.FileSystemObject")
objStartFolder = "Notes"
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
If UCase(objFSO.GetExtensionName(objFile.name)) = "TXT" Then
document.write objFile.name & "<br>"
End If
Next
最佳答案
这会起作用:
...
For Each objFile in colFiles
If UCase(objFSO.GetExtensionName(objFile.name)) = "TXT" Then
document.write Left(objFile.name, Len(objFile.name)-4) & "<br>"
End If
Next
根据文档,Left()
Returns a specified number of characters from the left side of a string.
您只需要知道要返回多少个字符。由于您已经知道文件名以 .txt
结尾,因此您可以返回除最后 4 字符之外的所有字符。 Len(objFile.name)
将为您提供完整长度,您可以从中减去。
关于file - 从返回的文件列表中删除文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33091188/