代码之家  ›  专栏  ›  技术社区  ›  chanchal1987

For循环批处理编程

  •  1
  • chanchal1987  · 技术社区  · 15 年前

    我在如下目录中有一组文件:

    File-MyFile.txt
    File-AnotherFile.txt
    File-ThirdFile.txt

    我要重命名所有文件,如下所示:

    MyFile.txt
    AnotherFile.txt
    ThirdFile.txt

    我怎么能用 for 循环来做这个?

    2 回复  |  直到 15 年前
        1
  •  3
  •   clifgriffin    15 年前

    克里斯展示了最好的方法。我想这可能接近你的要求,尽管我没有测试:

    @echo off
    for /f %%a IN ('dir /b *.txt') do call :dorename %%a
    goto :eof
    
    :dorename
    set oldfile=%1
    set newfile=%oldfile:File-=%
    rename %oldfile% %newfile%
    
        2
  •  0
  •   chris    15 年前

    不需要for循环:

    rename File- "" File-*.txt