3

I am running a batch file and I have one forfiles command in it

FORFILES -p%spinputarchrootpath% -m*.csv -d-365 -c"CMD /C DEL @FILE"

%spinputarchrootpath% variable maps to a folder location (Y:\Temp Documents\testfolder).

Now the above command is throwing an error because of the space in the folder name (Temp Documents).

How to handle this space? I have tried putting quotes around %spinputarchrootpath% variable but it is not working.

double-beep
  • 5,031
  • 17
  • 33
  • 41
Sahil
  • 85
  • 1
  • 4
  • 8

4 Answers4

6

I'd the same problem and found the solution. I think your folder-variable of the folder you wish to empty has a backslash at the end.

This will NOT work:

echo J|forfiles /P "C:\temp files\" /S /M * /D -7 /C "cmd /c del /F /S /Q @path"

... but this works (without backslash)

echo J|forfiles /P "C:\temp files" /S /M * /D -7 /C "cmd /c del /F /S /Q @path"

Regards

Tino

Tino Korth
  • 61
  • 1
  • 1
3

Enclose the path in quotes:

FORFILES -p "%spinputarchrootpath%" -m *.csv -d -365 -c "CMD /C DEL @FILE"

Note, there's a space between -p and "%spinputarchrootpath%". Without a space in this case it won't work.

Andriy M
  • 76,112
  • 17
  • 94
  • 154
  • @Sahil: I don't know why I didn't pay attention initially, but now I see that you didn't put spaces after other parameters too. And I didn't either, but now I fixed my answer. – Andriy M Mar 07 '11 at 07:36
1

As a work around first change directories to the folder you want, and then execute forfiles without the /p parameter.

CD %spinputarchrootpath%
FORFILES -m*.csv -d-365 -c"CMD /C DEL @FILE"
yoel halb
  • 12,188
  • 3
  • 57
  • 52
1

Check post: How to Tell FORFILES to Execute Command on Path?

The problem lies in the part: -c"CMD /C DEL @FILE"

Use: -c"CMD /C DEL ^0x22@FILE^0x22" to put extra double quotes around the file

Community
  • 1
  • 1