批/ CMD:查找每个文件夹文件meta.xml(Batch/CMD: Finding out every single folder file meta.xml)

我有一个目录,其中包含以下内容:

-directory -another directory -meta.xml -yet another directory -meta.xml ...

所以它需要在每个目录中找到'meta.xml',这一切都是由它自己完成的(这样我就不必在代码中输入每个目录)并且我希望每个目录都有一个命令完成。

是否有任何可能的方式来做到这一点,这可以安静地完成,因为我说的命令给出了一个meta.xml文件的文本行,我不想看看它做了什么,你会得到这样的东西:

text from meta file 1 text from meta file 2 text from meta file 3

并不是

meta.xml found text from meta file 1 meta.xml found text from meta file 2 meta.xml found text from meta file 3

如果那不清楚,只是想我会喜欢它安静地运行,好吧。 (/ Q也许?)

这是我所说的命令:

findstr "<name>" meta.xml >temp1.lis FOR /F "tokens=2 delims=>" %%i in (temp1.lis) do @echo %%i > temp2.lis FOR /F "tokens=1 delims=<" %%i in (temp2.lis) do @echo %%i > temp3.lis

它需要为每个meta.xml文件执行此操作,并提供输出,以便在您完成时获得完整列表

type temp3.lis

谢谢!

i have a directory which contains the following:

-directory -another directory -meta.xml -yet another directory -meta.xml ...

So it needs to find in every directory 'meta.xml', all by itself (so that i dont have to type in every directory at the code) And i want that with EVERY meta.xml file a command is done.

Is there ANY possible way to do this, and could this be quiet done because the command i was talking about gives a text line from that meta.xml file, and i would like to not see whats its doing, that you get something like this:

text from meta file 1 text from meta file 2 text from meta file 3

and not

meta.xml found text from meta file 1 meta.xml found text from meta file 2 meta.xml found text from meta file 3

If thats not clear, just think that i would just to like it run quietly, ok. (/Q maybe?)

this is the command i was talking about:

findstr "<name>" meta.xml >temp1.lis FOR /F "tokens=2 delims=>" %%i in (temp1.lis) do @echo %%i > temp2.lis FOR /F "tokens=1 delims=<" %%i in (temp2.lis) do @echo %%i > temp3.lis

it needs to do this for every single meta.xml file and giving the output so you get a total list when you do

type temp3.lis

Thanks!

最满意答案

好吧,据我所知,这应该工作:

findmeta.cmd

@echo off for /f "delims=" %%f in ('dir /b /s meta.xml') do ( FOR /F "tokens=2 delims=>" %%i in ('findstr "<name>" %%f') do @echo %%i > temp2.lis FOR /F "tokens=1 delims=<" %%i in (temp2.lis) do @echo %%i >> temp3.lis )

我修改了脚本部分,以便将答案添加到temp3.lis中,而不是替换它,并删除了第一个临时文件的使用。

如果最终你想要的是标签之间的东西,比如说 <name > blahblah </name >blahblah部分)

这应该做的更快,没有临时文件需要,少一个for循环 (为了便于阅读而分成多行,如果需要,它们都保留在单行上。

for /f "delims=" %%f in ('dir /b /s meta.xml') do ( FOR /F "tokens=2 delims=><" %%i in ('findstr "<name>" %%f') do ( @echo %%i >> temp3.lis ) )

单行版本:

for /f "delims=" %%f in ('dir /b /s meta.xml') do FOR /F "tokens=2 delims=><" %%i in ('findstr "<name>" %%f') do @echo %%i >> temp3.lis

不确定你喜欢哪一种, 如果这是你想要的。

编辑: 好吧,我认为我知道了,但我不确定它会解决所有问题。 基本上你想要将令牌= 2更改为令牌= 3,如下所示:

for /f "delims=" %%f in ('dir /b /s meta.xml') do FOR /F "tokens=3 delims=><" %%i in ('findstr "<name>" %%f') do @echo %%i >> temp3.lis

现在看看这是否有效。

Ok, as far as I can tell, this should work:

findmeta.cmd

@echo off for /f "delims=" %%f in ('dir /b /s meta.xml') do ( FOR /F "tokens=2 delims=>" %%i in ('findstr "<name>" %%f') do @echo %%i > temp2.lis FOR /F "tokens=1 delims=<" %%i in (temp2.lis) do @echo %%i >> temp3.lis )

I modified your script part so answers are added to temp3.lis, instead of replacing it, and removed the use of the first temp file.

If, in the end, what you're looking for is what ever is between the tags, like <name>blahblah</name> (the blahblah part)

this should do even faster, no temp files needed and one less for loop (broke into multiple lines for ease of reading, it all hold on a single line if needed.

for /f "delims=" %%f in ('dir /b /s meta.xml') do ( FOR /F "tokens=2 delims=><" %%i in ('findstr "<name>" %%f') do ( @echo %%i >> temp3.lis ) )

Single line version:

for /f "delims=" %%f in ('dir /b /s meta.xml') do FOR /F "tokens=2 delims=><" %%i in ('findstr "<name>" %%f') do @echo %%i >> temp3.lis

Not sure which you prefer, IF this is what you're looking for.

EDIT: Ok I think I got it, but I'm not sure it's gonna fix everything. Basically you want to change the tokens=2 to tokens=3 like this:

for /f "delims=" %%f in ('dir /b /s meta.xml') do FOR /F "tokens=3 delims=><" %%i in ('findstr "<name>" %%f') do @echo %%i >> temp3.lis

Now see if this works.

批/ CMD:查找每个文件夹文件meta.xml(Batch/CMD: Finding out every single folder file meta.xml)

我有一个目录,其中包含以下内容:

-directory -another directory -meta.xml -yet another directory -meta.xml ...

所以它需要在每个目录中找到'meta.xml',这一切都是由它自己完成的(这样我就不必在代码中输入每个目录)并且我希望每个目录都有一个命令完成。

是否有任何可能的方式来做到这一点,这可以安静地完成,因为我说的命令给出了一个meta.xml文件的文本行,我不想看看它做了什么,你会得到这样的东西:

text from meta file 1 text from meta file 2 text from meta file 3

并不是

meta.xml found text from meta file 1 meta.xml found text from meta file 2 meta.xml found text from meta file 3

如果那不清楚,只是想我会喜欢它安静地运行,好吧。 (/ Q也许?)

这是我所说的命令:

findstr "<name>" meta.xml >temp1.lis FOR /F "tokens=2 delims=>" %%i in (temp1.lis) do @echo %%i > temp2.lis FOR /F "tokens=1 delims=<" %%i in (temp2.lis) do @echo %%i > temp3.lis

它需要为每个meta.xml文件执行此操作,并提供输出,以便在您完成时获得完整列表

type temp3.lis

谢谢!

i have a directory which contains the following:

-directory -another directory -meta.xml -yet another directory -meta.xml ...

So it needs to find in every directory 'meta.xml', all by itself (so that i dont have to type in every directory at the code) And i want that with EVERY meta.xml file a command is done.

Is there ANY possible way to do this, and could this be quiet done because the command i was talking about gives a text line from that meta.xml file, and i would like to not see whats its doing, that you get something like this:

text from meta file 1 text from meta file 2 text from meta file 3

and not

meta.xml found text from meta file 1 meta.xml found text from meta file 2 meta.xml found text from meta file 3

If thats not clear, just think that i would just to like it run quietly, ok. (/Q maybe?)

this is the command i was talking about:

findstr "<name>" meta.xml >temp1.lis FOR /F "tokens=2 delims=>" %%i in (temp1.lis) do @echo %%i > temp2.lis FOR /F "tokens=1 delims=<" %%i in (temp2.lis) do @echo %%i > temp3.lis

it needs to do this for every single meta.xml file and giving the output so you get a total list when you do

type temp3.lis

Thanks!

最满意答案

好吧,据我所知,这应该工作:

findmeta.cmd

@echo off for /f "delims=" %%f in ('dir /b /s meta.xml') do ( FOR /F "tokens=2 delims=>" %%i in ('findstr "<name>" %%f') do @echo %%i > temp2.lis FOR /F "tokens=1 delims=<" %%i in (temp2.lis) do @echo %%i >> temp3.lis )

我修改了脚本部分,以便将答案添加到temp3.lis中,而不是替换它,并删除了第一个临时文件的使用。

如果最终你想要的是标签之间的东西,比如说 <name > blahblah </name >blahblah部分)

这应该做的更快,没有临时文件需要,少一个for循环 (为了便于阅读而分成多行,如果需要,它们都保留在单行上。

for /f "delims=" %%f in ('dir /b /s meta.xml') do ( FOR /F "tokens=2 delims=><" %%i in ('findstr "<name>" %%f') do ( @echo %%i >> temp3.lis ) )

单行版本:

for /f "delims=" %%f in ('dir /b /s meta.xml') do FOR /F "tokens=2 delims=><" %%i in ('findstr "<name>" %%f') do @echo %%i >> temp3.lis

不确定你喜欢哪一种, 如果这是你想要的。

编辑: 好吧,我认为我知道了,但我不确定它会解决所有问题。 基本上你想要将令牌= 2更改为令牌= 3,如下所示:

for /f "delims=" %%f in ('dir /b /s meta.xml') do FOR /F "tokens=3 delims=><" %%i in ('findstr "<name>" %%f') do @echo %%i >> temp3.lis

现在看看这是否有效。

Ok, as far as I can tell, this should work:

findmeta.cmd

@echo off for /f "delims=" %%f in ('dir /b /s meta.xml') do ( FOR /F "tokens=2 delims=>" %%i in ('findstr "<name>" %%f') do @echo %%i > temp2.lis FOR /F "tokens=1 delims=<" %%i in (temp2.lis) do @echo %%i >> temp3.lis )

I modified your script part so answers are added to temp3.lis, instead of replacing it, and removed the use of the first temp file.

If, in the end, what you're looking for is what ever is between the tags, like <name>blahblah</name> (the blahblah part)

this should do even faster, no temp files needed and one less for loop (broke into multiple lines for ease of reading, it all hold on a single line if needed.

for /f "delims=" %%f in ('dir /b /s meta.xml') do ( FOR /F "tokens=2 delims=><" %%i in ('findstr "<name>" %%f') do ( @echo %%i >> temp3.lis ) )

Single line version:

for /f "delims=" %%f in ('dir /b /s meta.xml') do FOR /F "tokens=2 delims=><" %%i in ('findstr "<name>" %%f') do @echo %%i >> temp3.lis

Not sure which you prefer, IF this is what you're looking for.

EDIT: Ok I think I got it, but I'm not sure it's gonna fix everything. Basically you want to change the tokens=2 to tokens=3 like this:

for /f "delims=" %%f in ('dir /b /s meta.xml') do FOR /F "tokens=3 delims=><" %%i in ('findstr "<name>" %%f') do @echo %%i >> temp3.lis

Now see if this works.