Reputation: 23
I am using forfiles to delete files older than 7 days from a specific directory using the following script found elsewhere on this forum:
forfiles -p "H:\E-drev" -m *.* /D -7 /C "cmd /c del @path"
This Works fine except I have some files with no extension eg. a file named TA07l. This file is not deleted. I have tried using @fname
instead of @path
but this does not help.
Any advice would be greatly appreciated.
Upvotes: 2
Views: 4096
Reputation: 34989
The following should work:
forfiles /P "H:\E-drev" /M * /D -7 /C "cmd /C if @isdir==FALSE if @ext==\"\" del @path"
Upvotes: 2
Reputation: 2710
You have to use *
instead of *.*
because otherwise it will search every files that contain a dot .
Update with few examples between *
and *.
and *.*
:
copy nul _onefilewithoutext
copy nul _onefilewith.ext
mkdir _oneFolder
dir /b /a-d *.
_onefilewithoutext
Forfiles
command
forfiles /M *. /C "cmd /C echo @relpath"
Error: File Type "*." not found.
forfiles /M * /C "cmd /C echo @relpath"
".\_onefilewith.ext"
".\_onefilewithoutext"
".\_oneFolder"
forfiles /M *.* /C "cmd /C echo @relpath"
".\_onefilewith.ext"
forfiles /M * /C "cmd /C if @isdir==FALSE echo @relpath"
".\_onefilewith.ext"
".\_onefilewithoutext"
forfiles /M * /C "cmd /C if @isdir==FALSE if @ext==\"\" echo @relpath"
".\_onefilewithoutext"
Upvotes: 1