代码之家  ›  专栏  ›  技术社区  ›  Patrick Bender

使用批处理文件发送到

  •  0
  • Patrick Bender  · 技术社区  · 7 年前

    嗨,我有一个主文件夹,其中包含两个文件夹“活动”和“确认”。 这两个文件夹下的子文件夹是相同的。我希望能够通过windows上下文菜单选择需要发送到已确认文件夹的文件,但我无法使用此代码。

    for %%i in (%*) do (
        REM Takt the path of each file and save it as source.
        source=%%i
        REM Change the word "active" in the path to "confirmed".
        destnation=%%i:active=confirmed%
    
        REM Move the file to the confirmed subtree. 
        move /-Y source destination
    )
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Squashman Stephan    4 年前

    你需要使用 SET 命令将字符串分配给变量。也不能用 FOR

    试试这个。

    @echo off
    for %%I in (%*) do (
        REM Take the path of each file and save it as source.
        set "destination=%%~dpI"
        REM Change the word "active" in the path to "confirmed".
        setlocal enabledelayedexpansion
        set "destination=!destination:active=confirmed!"
        REM Move the file to the confirmed subtree. 
        move /-Y "%%~I" "!destination!"
        endlocal
    )