×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

forfiles

本文发表在 rolia.net 枫下论坛The Windows 2000 Resource Kits and Supplement One contains the FORFILES command, and an updated version is built into Windows .NET Server.

When you type FORFILES at a CMD prompt, you receive:

FORFILES v 1.1 - emmanubo@microsoft.com - 4/98

Syntax : FORFILES [-pPath] [-mSearch Mask] [-ccommand] [-d<+|->] [-s]

-pPath Path where to start searching
-mSearch Mask Search files according to
-cCommand Command to execute on each file(s)
-d<+|-> Select files with date >= or <=DDMMYYYY (UTC)
or files having date >= or <= (current date - DD days)
-s Recurse directories
-v Verbose mode

The following variables can be used in Command :
@FILE, @FNAME_WITHOUT_EXT, @EXT, @PATH, @RELPATH, @ISDIR, @FSIZE, @FDATE,
@FTIME

To include special hexa characters in the command line : use 0xHH

Default :
Examples :
FORFILES -pc:\ -s -m*.BAT -c"CMD /C Echo @FILE is a batch file"
FORFILES -pc:\ -s -m*.* -c"CMD /C if @ISDIR==TRUE echo @FILE is a directory"
FORFILES -pc:\ -s -m*.* -d-100 -c"CMD /C Echo @FILE : date >= 100 days"
FORFILES -pc:\ -s -m*.* -d-01011993 -c"CMD /C Echo @FILE is quite old!"
FORFILES -pc:\ -s -m*.* -c"CMD /c echo extension of @FILE is 0x22@EXT0x22"更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / 请教: 在DOS下, 怎么检查一个文件是不是空文件(0 Byte). 多谢.
    • C:\ DIR /O:S
      • 是想写个batch file, 如果是 0 Byte, 就直接delete了.
        • forfiles
          本文发表在 rolia.net 枫下论坛The Windows 2000 Resource Kits and Supplement One contains the FORFILES command, and an updated version is built into Windows .NET Server.

          When you type FORFILES at a CMD prompt, you receive:

          FORFILES v 1.1 - emmanubo@microsoft.com - 4/98

          Syntax : FORFILES [-pPath] [-mSearch Mask] [-ccommand] [-d<+|->] [-s]

          -pPath Path where to start searching
          -mSearch Mask Search files according to
          -cCommand Command to execute on each file(s)
          -d<+|-> Select files with date >= or <=DDMMYYYY (UTC)
          or files having date >= or <= (current date - DD days)
          -s Recurse directories
          -v Verbose mode

          The following variables can be used in Command :
          @FILE, @FNAME_WITHOUT_EXT, @EXT, @PATH, @RELPATH, @ISDIR, @FSIZE, @FDATE,
          @FTIME

          To include special hexa characters in the command line : use 0xHH

          Default :
          Examples :
          FORFILES -pc:\ -s -m*.BAT -c"CMD /C Echo @FILE is a batch file"
          FORFILES -pc:\ -s -m*.* -c"CMD /C if @ISDIR==TRUE echo @FILE is a directory"
          FORFILES -pc:\ -s -m*.* -d-100 -c"CMD /C Echo @FILE : date >= 100 days"
          FORFILES -pc:\ -s -m*.* -d-01011993 -c"CMD /C Echo @FILE is quite old!"
          FORFILES -pc:\ -s -m*.* -c"CMD /c echo extension of @FILE is 0x22@EXT0x22"更多精彩文章及讨论,请光临枫下论坛 rolia.net
          • 正解.
          • 谢谢了, 长见识了... 俺再琢磨琢磨.
      • 楼主可能不是这个意思。
    • 用VB Script最简单了。进来看。
      Dim Fso, Drives, Drive, Folder, Files, File, Subfolders,Subfolder
      Set Fso=createobject("scripting.filesystemobject")

      Set Drives=fso.drives

      For Each Drive in Drives
      If drive.isready then
      Dosearch (drive & "\")
      end If
      Next


      Function Dosearch(Path)
      wscript.echo "Processing folder " & path
      Set Folder=fso.getfolder(path)
      Set Files = folder.files

      For Each File in files
      if file.size = 0 then
      wscript.echo path & file.name & " found size is 0. Deleted."
      fso.DeleteFile (path & file.name)
      end if

      Next

      Set Subfolders = folder.SubFolders
      For Each Subfolder in Subfolders

      Dosearch (Subfolder.path & "\")
      Next
      end function
      • 贴子把 "\" 给略掉了。在Dosearch参数里面,最后一个引号里面是一个back slash
    • I am using this script
      fc /b yourfile null | find "FC: no differences encountered" >null
      if errorlevel==2 goto _failed
      if errorlevel==1 if not errorlevel==2 goto _successed
      if errorlevel==0 if not errorlevel==1 goto _zerobyte
    • powerful perl
      $dir = "yourdir";
      opendir(DIR, $dir);
      while($file = readdir(DIR)) { if(-s $file) unlink($file); }
      closedir(DIR);

      NOT TESTED, but 差不多这个意思。
      • perl is always my favorite scripting language, forfiles is a quick solution, for some sophisticated problem perl is my first choice.
        • yeah i'm a perl fan alough I'm not using it now. it's always succinct, powerful and elegant.
    • 都是能人啊! :-) 一直是用Perl的, 只是想看看有没有更简单的DOS command. 看来是没有比Perl更简单的, 又得劝劝super, 还是装Perl 吧. 谢谢大伙!