RSS

Forfiles

16 Apr

windows server 2008内置命令

开关很少,p路径,m 方式,s包含子目录,c执行命令,d日期

普通使用可能比不上for,dir等,但是c这个开关很强大的

command string:
@file    – returns the name of the file.
@fname   – returns the file name without extension.
@ext     – returns only the extension of the file.
@path    – returns the full path of the file.
@relpath – returns the relative path of the file.
@isdir   – returns "TRUE" if a file type is a directory, and "FALSE" for files.
@fsize   – returns the size of the file in bytes.
@fdate   – returns the last modified date of the file.
@ftime   – returns the last modified time of the file.

FORFILES /P C:\WINDOWS /S /M DNS*.*
列出windows及其子目录下DNS开头的所有文件

FORFILES /S /M *.txt /C "cmd /c type @file | more"
列出当前目录以及子目录下所有的txt文档的内容,并以分页的形式打印出来

FORFILES /P C:\ /S /M *.bat
列出windows及其子目录下的bat文件

FORFILES /D -30 /M *.exe /C "cmd /c echo @path 0x09 was changed 30 days ago"

列出30天内修改过的exe文件,列出路径+自定义文字0x09(tab) was changed 30 days ago

FORFILES /D 2001/01/01 /C "cmd /c echo @fname is new since Jan 1st 2001"

列出2001、0101后的文件并打印文档名字+is new since Jan 1st 2001

FORFILES /D +2009/4/10 /C "cmd /c echo @fname is new today"

列出20090410后修改过的文件,并打印

FORFILES /M *.exe /D -1

列出一天前到现在修改过的exe文件
FORFILES /S /M *.doc /C "cmd /c echo @fsize"

列出doc文件,并打印出文件大小

FORFILES /M *.txt /C "cmd /c if @isdir==FALSE notepad.exe @file"

列出txt文件,如果不是文件夹,那么就依次用notepad打开该文件,关闭后开启下一个文件。

—————-

以上是help文档,加强版

forfiles /m *.log /c "cmd /c del @file"
 
forfiles /m *.log /c "cmd /c if @fsize geq 1000000 (del @file)"
 
forfiles /m *.log /c "cmd /c if @fsize geq 1000000 (del @file) Else (move @file c:\archive)"
 
forfiles /m *.log /c "cmd /c if @fsize geq 1000000 (echo @file is 1MB or larger) Else (echo @file is 1MB less)"

嵌套IF/else

Advertisements
 
1 Comment

Posted by on April 16, 2009 in Cmdlets&Tools

 

Tags:

One response to “Forfiles

  1. April 16, 2009 at 19:32

    这个很不错,非常实用的工具

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: