如何逃避`forfiles`了`@`变量替换? [英] How to escape the `@` variable replacement in `forfiles`?

查看:112
本文介绍了如何逃避`forfiles`了`@`变量替换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是这样(的Windows 7 x64)的一个 FORFILES 命令行:

I am using a forfiles command line like this (Windows 7 x64):

forfiles /P "C:\root" /M "*.txt" /C "cmd /C echo @relpath"

我怎样才能逃避替换 @relpath 的(相对路径当前迭代的项),以获得 @relpath 输出字面上? (......或任何其他 @ 变量?)

How can I escape the replacement of @relpath (relative path to currently iterated item) to get @relpath output literally? (...or any other @ variable?)

到目前为止,我尝试了以下的东西,没有成功:

So far I tried the following things, without success:


  • \\ :在 @ 似乎之前 \\ 所以 \\ @ relpath 不工作,而扩展输出仅仅是preceded与 \\ ;

  • ^ :说明 ^ @ 不显示除任何作用了 ^ 消失;写 ^^ @ 不非此即彼的帮助,有一个 ^ 仍然在扩展输出即可;

  • 0xHH :令人惊讶的(对我来说),在 FORFILES 特异性更换hexacecimal号 0X40 也不起作用,看来,这是变量解析之前完成;

  • @@ :加倍 @ 保持第一 @ 从字面上看,就是它了;

  • \: the @ seems to be handled before \ so \@relpath does not work, rather the expanded output is just preceded with \;
  • ^: stating ^@ does not show any effect except that the ^ disappears; writing ^^@ does not help eigher, one ^ remains in the expanded output then;
  • 0xHH: surprisingly (to me), the forfiles-specific replacement of hexacecimal numbers 0x40 does not work either, it seems that this is done prior to variable parsing;
  • @@: doubling the @ keeps the first @ literally, that is it;

推荐答案

我刚刚找到一种更简单的方法:

I just found an even easier method:

forfiles /P "C:\root" /M "*.txt" /C "cmd /C echo @^relpath"

请注意在 ^ 之后的的 @ 标志。

这篇关于如何逃避`forfiles`了`@`变量替换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆