You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

寻求支持中文与拉丁字符的Dir.bat等效命令

解决dir命令输出中文显示为问号的方案

方案一:修改CMD编码后执行

默认CMD使用OEM编码(如GBK),重定向输出时编码不匹配会导致中文乱码。通过切换到UTF-8编码可解决:

cmd /c chcp 65001 >nul & dir /b > "%temp%\Dir.txt" & notepad "%temp%\Dir.txt"
  • chcp 65001:将CMD编码切换为UTF-8
  • >nul:屏蔽编码切换的提示信息,避免写入结果文件
  • 后续的dir /b和notepad命令保持原有逻辑,此时输出的文件为UTF-8编码,中文可正常显示

方案二:使用PowerShell替代CMD

PowerShell原生支持Unicode,对中文兼容性更好,可直接用以下命令实现等效功能:

powershell -Command "Get-ChildItem -Name | Out-File -FilePath '%temp%\Dir.txt' -Encoding utf8; notepad '%temp%\Dir.txt'"

或者更简洁的写法:

powershell "Get-ChildItem -Name > '%temp%\Dir.txt'; notepad '%temp%\Dir.txt'"

注:> 在PowerShell中默认用UTF-16编码输出,若需要确保文件为UTF-8,推荐使用带-Encoding utf8的版本,兼容性更强。

内容的提问来源于stack exchange,提问作者Deuteronomy93

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 21:22:01