嗨我有一个包含两个文件夹的主文件夹"活动"并且"确认"。 这两个文件夹下的子文件夹是相同的。我希望能够通过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
)
答案 0 :(得分:2)
您需要使用SET
命令将字符串分配给变量。您也不能使用FOR
变量进行字符串替换。您还需要使用延迟扩展来引用代码块中的变量。
试一试。
@ech 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
)