简体   繁体   English

Windows批处理-尝试合并所有子目录中具有相同名称的文本文件时出现空文件

[英]Windows Batch - empty files while trying to merge text files with the same name from all subdirectories

I have already found in a different topic, How to merge text files with the same name from all subdirectories? 我已经在另一个主题中找到了如何合并所有子目录中具有相同名称的文本文件? , the following code to merge the files with a batch: ,以下代码将文件与批处理合并:

@echo off
  for /r "." %%a in (*.txt) do (
    echo %%~na
    type %%a >> %%~na-merged.txt
  )

In my local pc this works fine. 在我的本地PC上,效果很好。 But, when I try this on a windows server we use in a VDI, the new files are created empty. 但是,当我在用于VDI的Windows服务器上尝试此操作时,新文件将创建为空。 You may find below the information from cmd: 您可以在以下cmd的信息中找到:

'ááá' is not recognized as an internal or external command, operable program or batch file. “ááá”未被识别为内部或外部命令,可操作程序或批处理文件。 'áááecho' is not recognized as an internal or external command, operable program or batch file. 'ááecho'不被识别为内部或外部命令,可操作程序或批处理文件。 'ááá' is not recognized as an internal or external command, operable program or batch file. “ááá”未被识别为内部或外部命令,可操作程序或批处理文件。 Access is denied. 访问被拒绝。 Error occurred while processing: D:... The system cannot find the file specified. 处理时发生错误:D:...系统找不到指定的文件。 Error occurred while processing: -. 处理时发生错误:-。 The system cannot find the path specified. 该系统找不到指定的路径。 Press any key to continue . 按任意键继续 。 . .

Can anyone help? 有人可以帮忙吗?

Single line from the appropriate directory at the Command Prompt. 命令提示符下相应目录中的一行。

@(For /F "Delims=" %A In ('FindStr/SM $ "samename.txt"') Do @(Echo "%~A"&Type "%~A"))>"samename-merged.txt"

Change both instances of samename to your specific name specification. 将两个samename名称的实例更改为您的特定名称规范。

It worked by using the "~". 它通过使用“〜”来工作。

@for /r "." %%a in (*.txt) do (echo %%~na type "%%~a" >> %%~na-merged.txt)

Thanks again all of you for your help! 再次感谢大家的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM