cmd - 如何搜索目录中的所有txt文件(包括子文件夹)
问题描述
我想要一个可以查看目录的所有子文件夹并将txt文件的所有内容编译成一个的命令。
我有一个为文件夹执行此操作的代码。
@echo on
erase Compiled.txt
type *.txt>> Compiled.txt
我如何使它能够查看所有子文件夹?
谢谢
解决方案
如果您可以使用 PowerShell,则可以这样做。
$CompiledFile = '.\Compiled.txt'
if (Test-Path -Path $CompiledFile) { Remove-Item -Path $CompiledFile }
Get-ChildItem -File -Recurse -Filter '*.txt' |
ForEach-Object {
Get-Content $_.FullName | Out-File -FilePath $CompiledFile -Encoding ascii -Append
}
如果你必须在 1987 年的老式 cmd.exe 中运行,它可以被扭曲成可用的形式。
powershell -NoLogo -NoProfile -Command ^
"$CompiledFile = '.\Compiled.txt'" ^
"if (Test-Path -Path $CompiledFile) { Remove-Item -Path $CompiledFile }" ^
"Get-ChildItem -File -Recurse -Filter '*.txt' |" ^
" ForEach-Object {" ^
" Get-Content $_.FullName | Out-File -FilePath $CompiledFile -Encoding ascii -Append" ^
" }"
推荐阅读
- regex - 正则表达式查找 3 个字符子字符串中唯一字符的所有索引
- c++ - 带有默认模板参数的 C++ 类型别名和前向声明
- android - 管理设备以供公众使用并禁止特定应用程序使用
- java - 用于 Spring Boot 应用程序的带有 Application Insights 的结构化日志记录
- python - 如何将pdf字节文件转换为普通文件?
- mongodb - 我想知道如何为 Mongo DB 编写更新脚本
- javascript - 在 axios 中出现 SELF_SIGNED_CERT_IN_CHAIN 错误,但通过 curl 或邮递员传递
- sql - RANK() 如何在 Sql 中的多个列上工作?
- amazon-web-services - 设置 AWS S3 存储桶权限
- javascript - 为什么 HTML 属性在 DOM 中设置不同?