batch-file - 将多个文本文档附加到一个文档的批处理文件
问题描述
我创建了一个批处理文件,它应该做几件事,包括将某种格式的所有文本文档附加到一个文本文件中,前提是目录中有多个这种格式的文本文件。这部分代码如下:
:multiple
SET /a count=0
ECHO.> "%location%\UAV_camera_coords_all.txt"
FOR /r "%location%\Output" %%G in ("UAV_camera_coords_*.txt") do set /a count+=1
IF %count% GTR 1 (
FOR /r "%location%\Output" %%G in ("*.txt") DO (
SET file=%%~G
TYPE "%file%">>"%location%\UAV_camera_coords_all"
)
GOTO :end
即使 count 变量大于一,代码在到达 if 语句时似乎也会崩溃。if 语句中的任何代码都没有被执行,实际上也没有应该在 if 语句之后执行的代码。是否有任何语法或其他错误可能导致此问题?
解决方案
除了我的评论。我假设您并没有真正计划输入的输出,*.txt
而只是UAV_camera_coords_*.txt
.. 如果没有,请随时将其更改回*.txt
@echo off
for /f "tokens=1,*" %%i in ('dir /s "%location%\UAV_camera_coords_*.txt" ^| findstr "File(s)"') do set cnt=%%i
if %cnt% gtr 1 (
for /f %%a in ('dir /b /s "%location%\UAV_camera_coords_*.txt"') do type "%%~a"
)>"%location%\UAV_camera_coords-all.txt"
请注意,我将输出文件名更改为-all
,而不是_all
因为如果它也是一个文件,它会将文件键入到自身上txt
。
在我意识到您正在递归搜索目录之前,编辑添加回原始答案:
@echo off
for /f "tokens=1,*" %%i in ('dir "UAV_camera_coords_*.txt" ^| findstr "File(s)"') do if %%i gtr 1 type "UAV_camera_coords_*.txt">>"%location%\UAV_camera_coords_all"
推荐阅读
- c# - 为什么 try catch 异常会在 SSIS 中错误地报告文件路径?
- angular - 在 MatSnackBar 中使用“snackBar.openFromComponent()”方法时如何放置动作按钮?
- ios - 我如何与 Metal 沟通我正在避免 GPU 和 CPU 之间的数据冲突
- grammar - T-SQL 语法分析器规则与自身相互左递归
- reactjs - 如何在 React 中使用多个不间断空格?
- python - 使用 smptlib 发送的电子邮件缺少主题行
- c# - 如何使用 Eclipse 构建 Antlr4 C# 语法?
- java - 假阳性声纳问题
- javascript - 发出新的 websocket 请求时取消当前的 websocket 处理
- angular - 使用Angular 7获取“无法读取未定义的属性'http'”