问题描述:

So I am trying to create a batch file, that gets all the files in deletesrc and find's if it's name matches any folder in deletedest. To accomplish this, I have tried to generate a list of file names in deletesrc which is stored in deletefiles (in the format "first" "second" "third file"). Then I intend to loop through each folder in deletedest and check for it's existence in deletesrc (using this). So far I have managed:

setlocal enabledelayedexpansion

set "deletesrc=F:\Delete Source"

set "deletedest=C:\Users\Spaced Name\Delete\Dest"

set "deletefiles=" ::I think this is useless, but I would prefer it to be here

for /R "%deletesrc%\" %%i in (*) do (

set "deletefiles=!deletefiles!^"%%i^" "

::random comment that is source of error

)

set deletefiles=!deletefiles!:rTrim

echo !deletefiles!

The main problem is, I keep getting ) was unexpected at this time.

Placing an echo test as the first thing within the loop, does not change the output, implying the loop is not run and the error encountered first. Placing an echo just before the loop, does produce output and the error immediately after it.

If there are any syntax standards or things I should/should not be doing that do not answer the question, I would like to know.

网友答案:

Your problem is you're using :: as a comment inside your FOR loop. You can't do this because :: is actually the label designator and it is breaking the FOR loop.

Change this line:

::random comment that is source of error

To this:

REM random comment that is source of error

UPDATE

As foxidrive stated in the comments, you can use :: as a comment inside a FOR as long as it is not the last line before the closing ).

网友答案:

Try this:

 set deletefiles=!deletefiles! "%%i"
相关阅读:
Top