for %1 %%i in (*.*) do [...] not working

Discussion in 'Support' started by roytam1, Apr 15, 2010.

  1. roytam1

    Message Count:
    43
    Re: not working

    but with this script, it proves CMD not only have %CD% unchanged, but really not changing "current directory" by CD/CHDIR:
    Code:
    @echo off
    setlocal enabledelayedexpansion
    for /R %%i in (.) do call :disprpath "%%~i"
    endlocal
    GOTO :EOF
    
    rem sub disprpath(filename)
    :disprpath
     cd
     call :rpath "%~1"
     echo rpath = %rpath%
    GOTO :EOF
    
    rem sub rpath(filename) OUT: %rpath%
    :rpath
     rem debug print %1 here
     echo (rpath: %1)
     echo (CD in rpath: %CD%)
    
     SET rpath=%~1
     set rpath=!rpath:%CD%\=!
    GOTO :EOF
    CMD:
    H:\test>forx.bat
    H:\test
    (rpath: "H:\test\.")
    (CD in rpath: H:\test)
    rpath = .
    H:\test
    (rpath: "H:\test\dir1\.")
    (CD in rpath: H:\test)
    rpath = dir1\.
    H:\test
    (rpath: "H:\test\dir1\dir1-1\.")
    (CD in rpath: H:\test)
    rpath = dir1\dir1-1\.
    H:\test
    (rpath: "H:\test\dir2\.")
    (CD in rpath: H:\test)
    rpath = dir2\.

    TCC:
    [H:\test]forx.bat
    H:\test
    (rpath: "H:\test\.")
    (CD in rpath: H:\test)
    rpath = .
    H:\test\dir1
    (rpath: "H:\test\dir1\.")
    (CD in rpath: H:\test\dir1)
    rpath = .
    H:\test\dir1\dir1-1
    (rpath: "H:\test\dir1\dir1-1\.")
    (CD in rpath: H:\test\dir1\dir1-1)
    rpath = .
    H:\test\dir2
    (rpath: "H:\test\dir2\.")
    (CD in rpath: H:\test\dir2)
    rpath = .
  2. roytam1

    Message Count:
    43
    Re: not working

    I'll agree with you for TCC style variables. *BUT* not with CMD's !var! style delayed variables.
  3. rconn Administrator

    Message Count:
    5,804
    Re: not working

    The delayed expansion isn't relevant.

    I have no intention of duplicating this tortured syntax, because:

    1) It's undocumented by Microsoft (and IMO is more likely to be a bug than a
    feature)

    2) It's exceptionally goofy

    3) It's completely useless, as there's a simpler, documented, and actually
    used syntax that works in both CMD and TCC:

    Set _html=^^^<title^^^>Hello world ^^^</title^^^>
    Echo %_html%

    TCC also has an even simpler solution:

    Echo `<title>Hello world </title>`

    Rex Conn
    JP Software
  4. rconn Administrator

    Message Count:
    5,804
    Re: not working

    Already possibly (more easily); see my other post.

    Rex Conn
    JP Software

Share This Page