批处理第七章

来源:互联网 发布:苏州园区软件培训 编辑:程序博客网 时间:2024/05/18 01:19

     

  1. 监控文件夹

  2.  

    @ECHO off

    set /p dir1=请输入你要监控的文件夹:

    @cd /d %dir1%

    :begin

    echo.>%temp%/hello.txt

    @for /F "delims==" %%i in ('dir /b *.*') do (

    @find "%%i" %temp%/hello.txt>nul

    if errorlevel==1 msg %username% "%%i%

    if errorlevel==0 echo %%i>>%temp%/hello.txt

     )

    ping -n 0 127.1>nul

    goto :begin

     

     

     

  3. 计数

  4.  

    @for /f "delims=" %%i in ('dir /s /b "*.exe"') do (  set /a a+=1) 

    cls

    echo %a%

    pause

     

     

  5. 遍历目录下的文件个数

  6.  

     

    @echo off

    mode 150

    set /p address=请输入你想要遍历的路径:

    set /p str=请输入你想要遍历的文件:

     

    @call :sub2 "%address%"

     

    @:sub2

    rem @if exist %1 (cd %1) 

    cd /d %1

    @for /f "delims==" %%i in ('dir /a:d /b') do (

    echo %%~fi

    @call :sub1 "%%i"

    @call :sub3 "%%i" 

    )

    goto end

    @goto :eof 

     

     

    @:sub3

    rem @if exist %1 (cd %1)

    cd /d %1

    @for /f "delims==" %%i in ('dir /a:d /b') do (

     

    @call :sub1 "%%i"

    )

    @cd..

    @goto :eof 

     

     

    @:sub1 

    @cd /d %1

    set /a a=0

    @for /f "delims==" %%j in ('dir /b %str%') do (set /a a+=1)

     echo         %a%  %1>>c:/dir.txt

     

    @cd..

    @goto :eof 

     

    :end

    set path=%path%;c:/windows

    start notepad.exe c:/dir.txt

     

    pause

    exit

     

     

  7. 获取目录下的文件列表

  8. @echo off 
    REM mode 200
    REM  for /f "delims==" %%i in ('dir /a:d /b') do (
    REM echo %%i 
    REM cd %%i
    REM  dir /s /b /p *.exe
    REM echo ----------------------------------
    REM                                                            
    REM cd..
    REM
    REM )
    @for /f "delims=" %%i in ('dir /s /b "*.exe"') do (  
    set /a a+=1
        ) 
    echo.
    echo NSI文件总数为:%a% 
    echo.
    set /a a=0
    @for /f "delims=" %%j in ('dir /s /b "*.exe"') do (  
    set /a a+=1
        ) 
    echo.
    echo EXE文件总数为:%a% 
    echo.
    set /a a=0
    @for /f "delims=" %%j in ('dir /a:d /b') do (  
    set /a a+=1
        ) 
    echo.
    echo DIRECTORY文件总数为:%a% 
    echo.
    pause

     

原创粉丝点击