2017-09-27 84 views
0

嗨,我有一个主文件夹,其中包含两个文件夹“活动”和“确认”。 这两个文件夹下的子文件夹是相同的。我希望能够通过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 
) 

回答

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 
) 
+0

谢谢你的职位遗憾的是它没有工作,我在这个新太能理解它做什么,但我刚开始的教育,以了解更多:) –

+0

@PatrickBender,它应该做你想要什么它根据你的问题的描述来做。您正在将文件拖放到活动文件夹的批处理文件中。您说路径结构与活动文件夹和已确认文件夹的路径结构相同,因此我们只需将活动一词更改为确认即可。然后它将放到批处理文件中的文件移动到已确认的文件夹,并在已有文件已存在的情况下提示您覆盖。 – Squashman

+0

真棒,我一定错过了一些事情,现在它运作良好! –