Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forfiles - spaces in folder path

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.

like image 301
Sahil Avatar asked Sep 01 '25 10:09

Sahil


1 Answers

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

like image 191
Tino Korth Avatar answered Sep 03 '25 14:09

Tino Korth