本文介绍了转义在FOR语句中的findstr中使用的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我尝试了最流行的可用解决方案(1) (2)

Yeah, I've tried the most popular available solutions(1)(2)

他们没有太大帮助;只是重申了我已经知道的东西.

They didn't help much; just restated what I already knew.

这有效:

@echo on
set var=APPENDTEXT
for /f "delims=" %%a in ('dir *.* /b /a-d') do ren "%%a" "%%~na%var%%%~xa"
pause

但是我尝试像这样对它进行细化

but then I try to refine it a bit like so

@echo on
set var=APPENDTEXT
for /f "delims=" %%a in ('dir *.* /b /a-d | findstr /v /i "\.bat$" ') do ren "%%a" "%%~na%var%%%~xa"
pause

这样我就不会最终重命名批处理文件本身. 但是后来一切都搞砸了.

so that I do not end up renaming the batch file itself. But then everything got messed up.

我已经尝试了几种转义的方法,没有一种能像我希望他们那样工作.

I've tried several approaches for escaping, none working quite like I want them to.

  1. ('dir ./b/a-d | findstr/v/i" .bat $"')
  2. ('dir ./b/a-d | findstr/v/i \.bat $ \"')
  3. ('dir ./b/a-d | findstr/v/i ^.bat $ ^"')
  1. ('dir . /b /a-d | findstr /v /i "".bat$"" ')
  2. ('dir . /b /a-d | findstr /v /i \".bat$\" ')
  3. ('dir . /b /a-d | findstr /v /i ^".bat$^" ')

逃脱它的正确方法是什么? *

我要它做什么?

简单地说,

What I want it to do ?

Simply put,

推荐答案

您已经正确地转义了findstr语句,但是管道|符号仍然需要转义.

| findstr  ;  →   ^| findstr

You have escaped the findstr statement correctly, but the pipe | symbol still needs to be escaped.

| findstr   →    ^| findstr

@echo on
set var=APPENDTEXT
for /f "delims=" %%a in ('dir *.* /b /a-d ^| findstr /v /i "\.bat$" ') do ren "%%a" "%%~na%var%%%~xa"
pause

这篇关于转义在FOR语句中的findstr中使用的符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 02:25