text - VBS OpenTextFile returns unexpected result
问题描述
This is my code:
Set fso = CreateObject("Scripting.FileSystemObject")
strText = fso.OpenTextFile(strLocalFolderName & "\" & Oudste).ReadAll()
msgbox strText
But strText
contains rubbish after these lines.
How can that be?
解决方案
该死!OpenTextFile 示例中的布尔选项经常被忽略!
fso.OpenTextFile(Path, ForReading, False, TriStateTrue)
路径是文件的路径。对于只读,ForReading 应该为 1。
那么这个 False 是经常被省略的布尔值(false 表示它没有被写入)
只有正确添加布尔值时,您才能选择一种txt文件。
在我的例子中是 unicode,所以我选择 -1 作为 Tristate。
提示:如果您使用文本文件得到奇怪的结果,请在记事本中打开,选择另存为,然后它会显示您实际拥有的文本类型。
推荐阅读
- lxml - spyne 生成无效架构
- java - JNA KeyboardUtils.isPressed 不使用箭头键
- django - 我不知道如何在 django 中显示 formset
- bash - 将输入文件中的多个参数多次传递给命令(Bash)
- appkit - 自定义 NSWindowController 中的级联
- asp.net-core - ASP.NET Core 2.2 - SignalR 如何加入群组并从服务器发送消息?
- javascript - 如何将变量传递给 CSS 网格 repeat() 函数
- jdbc - 如何使用存储过程配置 Kafka JDBC 源连接器?
- javascript - 将对象转换为javascript中的字符串,没有键中的引号
- java - 使用 Spring 在 H2 中列出类型字段