forfiles with UNC path

瘦欲@ 提交于 2019-11-27 14:54:48

问题


I am trying to use forfiles to delete files that are older than 7 days. The files are in a UNC path. Below is the script that I am using.

Forfiles -p \\devexpress\C$\FULL\ -s -m *.* -d -7 -c "cmd /c del /q @path" 

But I get an error mentioning that UNC paths (\machine\share) are not supported.

There appears to be workarounds available but cannot get a clear answer googling.


回答1:


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?




回答2:


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.




回答3:


I got this to work:

PushD "\\DS\Tajana\Arhiva\Arhive po danima" &&("forfiles.exe" /s /m "*.*" /d -7 /c "cmd /c del @path") & PopD

although I get a message about the error in cmd window "not supporting UNC Path" but it still deletes files older than 7 days



来源:https://stackoverflow.com/questions/7503491/forfiles-with-unc-path

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!