!var之间的区别!和批处理文件中的%var%

时间:2016-08-22 07:58:29

标签: batch-file cmd

旗帜延迟扩张'在批处理文件中启用。它始于:

    @echo off
    setlocal EnableDelayedExpansion

批处理文件打算生成所有' .c'当前文件夹及其所有子文件夹中的文件。这是:

    :: -------------------
    :: Generate file tree
    :: -------------------
    @echo off
    setlocal EnableDelayedExpansion
    for /f %%a in ('copy /Z "%~f0" nul') do set "CR=%%a"

    :: 1. Delete old file trees
    :: -------------------------

    for /r %%x in (*FileTree.txt) do (
        REM echo."File %%x deleted"
        del "%%x"
    )

    :: 2. Generate new file tree
    :: -------------------------

    break > localFileTree.txt

    set mypath=
    set localPath=
    call :treeProcess
    goto :eof

    :treeProcess
    setlocal
    for %%f in (*.c) do (
        set localPath=%mypath%%%f
        echo.!localPath! >> %~dp0\localFileTree.txt
    )
    for /D %%d in (*) do (
        set mypath=%mypath%%%d\
        echo.!mypath!
        cd %%d
        call :treeProcess
        cd ..
    )
    endlocal

    exit /b

可以通过多种方式引用变量:

  • 没有任何东西:mypath=...
  • 带有前导双百分号:%%f%%d
  • 两边都有百分号:%mypath%
  • 两边都带有感叹号:!mypath!

我有点困惑。我知道它与“延迟扩张”有关。打开的标志。但是这些变量引用如何实际上彼此不同?

0 个答案:

没有答案