원도우에서

유닉스의 find mtime 같은 명령을

실행 시키고 싶을 때

배치 스트립트로 가능하지만

ms에서 제공하는 forfiles 이라는 명령어를 사용 하면 된다.

그러나.. xp에서는 기본 제공 하지 않아...

ftp://ftp.microsoft.com/Reskit/y2kfix/x86/

요기 가서 다운을 받자~

(2003서버에서는 기본 제공함)

forfiles /p "C:\특정디렉토리" /M "*.*" /D -10 /C "CMD /C del @FILE"

/p : 디렉토리 지정

/m : 파일 지정

/d : 날짜 지정

예1) 웹로직 디렉토리의 access 로그를 현재부터 3일 이전은 삭제한다.

forfiles /p "C:\weblogic\\logs" /M "access.*" /D -3 /C "CMD /C del C:\weblogic\\logs\@file"

예2)MS에서

C: 드라이브에 있는 모든 배치 파일의 목록을 표시하려면 다음과 같이 입력합니다.

forfiles /p c:\ /s /m*.bat /c"cmd /c echo @file is a batch file"

C: 드라이브에 있는 모든 디렉터리의 목록을 표시하려면 다음과 같이 입력합니다.

forfiles /p c:\ /s /m*.* /c"cmd /c if @isdir==true echo @file is a directory"

C: 드라이브에 있는 100일 이상된 모든 파일의 목록을 표시하려면 다음과 같이 입력합니다.

forfiles /p c:\ /s /m*.* /dt-100 /c"cmd /c echo @file : date >= 100 days"

C: 드라이브에 있는 1993년 1월 1일 이전의 모든 파일을 나열하고 해당 파일에 대해 "file is quite old!"를 표시하려면 다음과 같이 입력합니다.

forfiles /p c:\ /s /m*.* /dt-01011993 /c"cmd /c echo @file is quite old!"

C: 드라이브에 있는 모든 파일의 확장명을 열 형식으로 나열하려면 다음과 같이 입력합니다.

forfiles /p c:\ /s /m*.* /c "cmd /c echo extension of @file is 0x09@ext0x09" With:

C: 드라이브에 있는 모든 배치 파일의 목록을 표시하려면 다음과 같이 입력합니다.

forfiles /p c:\ /s /m *.bat /c "cmd /c echo @file is a batch file"

C: 드라이브에 있는 모든 디렉터리의 목록을 표시하려면 다음과 같이 입력합니다.

forfiles /p c:\ /s /m *.* /c "cmd /c if @isdir==true echo @file is a directory"

C: 드라이브에 있는 100일 이상된 모든 파일의 목록을 표시하려면 다음과 같이 입력합니다.

forfiles /p c:\ /s /m *.* /d t-100 /c "cmd /c echo @file : date >= 100 days"

C: 드라이브에 있는 1993년 1월 1일 이전의 모든 파일을 나열하고 해당 파일에 대해 "file is quite old!"를 표시하려면 다음과 같이 입력합니다.

forfiles /p c:\ /s /m *.* /d t-01011993 /c "cmd /c echo @file is quite old!"

C: 드라이브에 있는 모든 파일의 확장명을 열 형식으로 나열하려면 다음과 같이 입력합니다.

forfiles /p c:\ /s /m*.* /c "cmd /c echo extension of @file is 0x09@ext0x09"

------------------사용방법---------------

K:\>forfiles
FORFILES v 1.1 - emmanubo@microsoft.com - 4/98

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

-pPath Path where to start searching
-mSearch Mask Search files according to <Search Mask>
-cCommand Command to execute on each file(s)
-d<+|-><DDMMYYYY|DD> 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 : <Directory : .> <Search Mask : *.*> <Command : "CMD /C Echo @FILE">
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"

2011/09/02 11:53 2011/09/02 11:53

Trackback Address :: https://youngsam.net/trackback/1503