1

I wanna use forfiles to delete files older than 92 days, but the code seems to be breaking. I have a dynamic folder name.

for /d %X in (e:\local\test\backups\s?????pbx\) do forfiles /p %X /m *.cab /c "cmd /c del @path" /d -92

I couldn't figure out where I am going wrong. Is there any other way to achieve this? Any help would be appreciated.

Hashmukh
  • 13
  • 3

2 Answers2

1

Windows commands only support wildcards in the terminal node of a path - It will not find paths that appear anywhere before the last \.

The solution for your problem is really simple :-) Just remove the final \

for /d %X in (e:\local\test\backups\s?????pbx) do forfiles /p %X /m *.cab /c "cmd /c del @path" /d -92
dbenham
  • 127,446
  • 28
  • 251
  • 390
0

Batch uses * as a wildcard character. Try this:

for /d %X in (e:\local\test\backups\s*pbx\) do forfiles /p %X /m *.cab /c "cmd /c del @path" /d -92
SomethingDark
  • 13,229
  • 5
  • 50
  • 55
  • I can see what's supposed to be happening, but what is actually happening? – SomethingDark Dec 16 '14 at 22:58
  • It was suppose to delete the files older than 92 days from directory e:\local\test\backups having subfolders "s*pbx". But I dont even see the echo command working instead of the delete command – Hashmukh Dec 16 '14 at 23:01
  • Just to be sure, you're running this on the command line instead of via a batch script, right? Because if this is inside a script, you need to use `%%X` instead of `%X`. – SomethingDark Dec 16 '14 at 23:05
  • try running `for /D %X in (E:\local\test\backups\s*pbx\) do echo %X` and see if anything comes up. There may be an issue with the outer `for` loop. – SomethingDark Dec 16 '14 at 23:36