2

I want to do some stuffs on images with extensions defined in a variable. The following script run well:

set AllowExt="jpg png bmp"
forfiles /p D:\Pictures /m *.* /c "cmd /c if not %AllowExt:jpg=% == %AllowExt% echo @file

But the following script throws error

set AllowExt="jpg png bmp"
forfiles /p D:\Pictures /m *.* /c "cmd /c if not %AllowExt:@ext=% == %AllowExt% echo @file"

ERROR: Invalid argument/option - 'png'. Type "FORFILES /?" for usage.

2 Answers 2

5

You might try this:

set "AllowExt=.jpg .png .bmp"
for %%a in (%AllowExt%) do (
  forfiles /p D:\Pictures /m *%%a /c "cmd /c echo @file"
)

"cmd /c echo @file" is the default command, see forfiles /?.

Sign up to request clarification or add additional context in comments.

1 Comment

Fixed as following and it ran okay. set AllowExt=.jpg .png .bmp for %%a in (%AllowExt%) do ( forfiles /p D:\Pictures /m *%%a /c "cmd /c echo @file" )
1

This should get you the filenames you need.

@echo off
set "AllowExt=jpg png bmp"
set "AllowExt= %AllowExt%"
set "AllowExt=%AllowExt: = *.%"
  pushd "D:\Pictures"
   for %%a in (%AllowExt%) do (
     echo "%%a"
   )
  popd

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.