1

no matter what i try, i don't get the following line in a batch file on my win7 64-bit machine to work:

forfiles /P "I:\testroot" /C "CMD /C if /i @FILE==testung.txt del /s @FILE"

The code runs, no error is shown but the file testung.txt is not deleted.

If someone is interested in the official syntax from MS:

http://technet.microsoft.com/de-de/library/cc753551%28v=ws.10%29.aspx

So where is the problem?

  • I:\testroot shouldn't be in quotes, according to the TN article – Wutnaut Jun 23 '14 at 17:40
  • doesn't matter, i already tried.. – user54512 Jun 23 '14 at 17:45
  • Where can I find more information on '@FILE', my googlefu isn't working – Wutnaut Jun 23 '14 at 17:58
  • under the link above in the article there is way down a section where they explain all the @Variables (are those really variables? the kinda look it) – user54512 Jun 23 '14 at 19:26
2

You missed a couple of double-quotes...

What's going on is that @FILE returns the file name wrapped in double-quotes, so you need to reference it as such in your IF-statement comparison.

You can witness this by doing a forfiles /P "I:\testroot" /C "CMD /C echo @FILE", and seeing that testung.txt is echoed as "testing.txt".

To use double-quotes within a string (instead of as a string delimiter) you need to escape them with a \.

So once we do that, it should work:

forfiles /P "I:\testroot" /C "CMD /C if /i @FILE==\"testung.txt\" del /s @FILE"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.