2017-09-27 82 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

真棒,我一定錯過了一些事情,現在它運作良好! –