简体   繁体   中英

Batch file Looping through files in a set directory returning errors

I'm trying to loop through and print a list of all files in a directory, the directory is being set by 2 different arguments, but I keep getting the following error

The syntax of the command is incorrect

I'm not really sure where im going wrong though as when i echo out the variables they are echoing correctly.

My code is as follows;

@echo off

setlocal

set "parent=C:\Users\Test\script\files"
set "addon=GROWTH"

setlocal enableDelayedExpansion
for %%X in ("%parent%\%addon%\*") do (
    echo %%~dpnX
)

endlocal
endlocal

So basically, i just want it to list all the files in the C:\\Users\\Test\\script\\files\\GROWTH directory.

Any help would be much appreciated.

The code does not have any issues as it is working. I suspect that you are only having issues with the locations of your opening parentheses So to see if this is indeed the case, try this one. we do not need the parentheses as it is a single command to follow the for statement:

@echo off
set "parent=C:\Users\Test\script\files"
set "addon=GROWTH"

for %%X in ("%parent%\%addon%\*") do echo %%~dpnX

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM