forfiles with UNC path

Enhanced solution to the PA's first answer is:

PushD "\\devexpress\C$\FULL\" &&(
    forfiles -s -m *.* -d -7 -c "cmd /c del /q @path" 
     ) & PopD

The PushD command maps the UNC path to free drive letter automatically, so this is portable approach. Found in http://www.petri.co.il/forums/showthread.php?t=24241.


The error I get when trying to reproduce the problem says that the problem is not with FORFILES not suporting UNC Path, but with CMD not being able to start with an UNC path as default directory. In case that this is also your problem, there are three approaches to solve it.

  1. you might assign the UNC path to a disk letter, via NET USE

    NET USE V: \\devexpress\C$
    Forfiles -p V:\FULL\ -s -m *.* -d -7 -c "cmd /c del /q @path" 
    
  2. You may bypass CMD and directly use some ERASEFILE executable utility directly in the -C option of the FORFILES

  3. You may bypass FORFILES and use FOR command with some date checking logic instead. See my answer to this Stack overflow question How can I check the time stamp creation of a file in a Windows batch script?