开发者

append all files of name johnsfiles.txt

开发者 https://www.devze.com 2023-03-16 17:13 出处:网络
I would like to append all files named johnsfiles.txt on my c drive. Thats every file with this n开发者_C百科ame regardless of sub directorys

I would like to append all files named johnsfiles.txt on my c drive.

Thats every file with this n开发者_C百科ame regardless of sub directorys

How do i achive this?


del allofjohnsfiles.txt
for /R %%a in (johnsfiles.txt) do type %%a >> allofjohnsfiles.txt


@Ryan Bemrose's solution is good in that it would produce the expected result (the merged contents of all the johnsfiles.txt files found). However it might also result in multiple error messages about missing files. The thing is, the FOR /R loop behaves differently depending on whether you specify a mask or an actual name in the brackets. In the former case it would only iterate over the files found, while in the latter case it would 'find' the specified file in all the folders in the branch, including those not actually containg the file. Seems like the name is perfectly ignored and the command simply iterates over all the subfolders.

That is a bit strange, and I couldn't overcome it otherwise than by using the output of the DIR /S /B command in the loop, like this:

@ECHO OFF
TYPE NUL >allofjohnsfiles.txt
FOR /F %%a IN ('DIR /S /B johnsfiles.txt') DO TYPE "%%a" >>allofjohnsfiles.txt


try

dir /s /B johnsfiles.txt > index.txt
0

精彩评论

暂无评论...
验证码 换一张
取 消