zoukankan      html  css  js  c++  java
  • 批处理读取INI文件

      Quote:

    1. @echo off
    2. :::::::::INI文件读取 by chenall QQ:366840202::::::::::::::::::::::
    3. ::使用方法:                                                        ::
    4. ::    inifile iniFilePath [section] [item]                        ::
    5. ::例子:                                                                ::
    6. ::        inifile c:\boot.ini                                        ::
    7. ::        读取c:\boot.ini的所有[section]                                ::
    8. ::        inifile c:\boot.ini "[boot loader]"                        ::
    9. ::        读取c:\boot.ini [boot loader]段的内容                        ::
    10. ::        inifile c:\boot.ini "[boot loader]" timeout                ::
    11. ::        显示c:\boot.ini [boot loader]段 timeout的值                ::
    12. ::                                                                ::
    13. ::::::::::::::::::::::::::::::::::::::::::::2006-12-18::::::::::::

    14. set item=
    15. set filepath=
    16. set section=
    17. setlocal EnableDelayedExpansion
    18. if not "%~1"=="" (
    19.         set filepath=%1
    20. ) else goto :file_err
    21. if not exist %filepath% goto :file_err
    22. if not "%~2"=="" (
    23.         set section=%2
    24.         if "!section:~0,1!"==""^" set section=!section:~1!
    25.         if "!section:~-1!"==""^" set section=!section:~0,-1!
    26. ) else goto :section
    27. if not "%~3"=="" (
    28.         set item=%3
    29.         if "!item:~0,1!"==""^" set item=!item:~1!
    30.         if "!item:~-1!"==""^" set item=!item:~0,-1!
    31. )
    32. setlocal disableDelayedExpansion
    33. set 字段开始=
    34. for /f "usebackq delims=[]" %%i in (`find /i "%section%" /n %filepath%`) do set 字段开始=%%i
    35. for /f "usebackq tokens=1* delims== skip=%字段开始%" %%i in (`type %filepath%`) do (
    36.         set a=%%i
    37.         setlocal EnableDelayedExpansion
    38.         if "!a:~0,1!"=="[" goto :eof
    39.         if not "!a:~0,1!"==";" (
    40.                 setlocal disableDelayedExpansion
    41.                 for /f "delims=;" %%x in ("%%i=%%j") do (
    42.                         if not DEFINED item (echo %%x) else (if /i "%%i"=="%item%" echo %%x)
    43.                 )
    44.         )
    45. )
    46. goto :eof

    47. :section
    48. setlocal disableDelayedExpansion
    49. for /f "usebackq delims== skip=2" %%i in (`find /i "[" %filepath%`) do echo %%i
    50. goto :eof

    51. :file_err
    52. setlocal disableDelayedExpansion
    53. echo.
    54. echo %1文件未找到或未输入!
    55. echo.
    56. goto :eof
            
    分享到: 更多
  • 相关阅读:
    Siri
    ArcSDE和Geodatabase10.1抢先版谍照介绍(3)——ArcToolbox工具和其他功能
    ‘马太’效应
    Linux琐屑下Resin JSP MySQL的布置和设置配备陈设2
    平安防御:分级防御对Linux服务器的攻击
    Linux无法解析域名的处理活动
    Ubuntu Linux Server的用户僻静后果分析
    大概要领确保确保Linux体系中SSH的安适性
    无错版Vsftpd Mysql Pam设置虚拟用户要领
    Redhat Linux AS4下的LAMP与Discuz装置1
  • 原文地址:https://www.cnblogs.com/tiasys/p/1123519.html
Copyright © 2011-2022 走看看