Doubts with conditional commands in BATCH files

1

What am I doing wrong?

cls
@echo COPIANDO ARQUIVOS JPEG

for %%f in (*.*) do (
if %%f equ *.jpg ( 
copy %%f "C:\Users\anezio\Desktop\Nova pasta (2)\imagem"
) else (
copy %%f "C:\Users\anezio\Desktop\Nova pasta (2)"
)
)
pause
    
asked by anonymous 25.11.2014 / 18:19

3 answers

1

You need to use a modifier to get the file extension. You will never have a file named *.jpg , which is what you are comparing. Using the ~x modifier as shown below should solve your problem.

cls
@echo COPIANDO ARQUIVOS JPEG

for %%f in (*.*) do (
if %%~xf equ .jpg ( 
copy %%f "C:\Users\anezio\Desktop\Nova pasta (2)\imagem"
) else (
copy %%f "C:\Users\anezio\Desktop\Nova pasta (2)"
)
)
pause
    
25.11.2014 / 18:26
0

:: issae

    cls
    @echo COPIANDO ARQUIVOS JPEG

    for %%f in (*.*) do (
            if "%%~xf" equ ".jpg" ( 
                    copy %%f "C:\Users\anezio\Desktop\Nova pasta (2)\imagem"
                    ) else (
                    copy %%f "C:\Users\anezio\Desktop\Nova pasta (2)"
                    )
            )
    pause
    
27.03.2015 / 03:46
0

2)checksifthereisajpgandpositive/negativecase,copypdestinationfolder   answeringthefilter

3)implementedacountedpjpg,othersandtotal

cd /d %~dp0 & cls && @echo off & setlocal enableextensions enabledelayedexpansion color 0a & mode con cols=100 lines=8 set _cnt_jpg=0 set _cnt_outros=0 set /a _cnt_total=!_cnt_jpg! + !_cnt_outros! for /f "tokens=* delims= " %%f in ('dir /a:-d /b /s *.*') do ( echo/ && Title Arquivos Copiados !_show_cnt_total:~-7! ... ( <nul echo/%%f | findstr /i /l /c:".jpg" ) 2>nul if "!errorlevel!" == "0" ( set /a _cnt_jpg=!_cnt_jpg! + 1 copy "%%~f" "%userprofile%\Desktop\Nova pasta (2)\imagem\" /v /y >nul 2>nul ) else ( set /a _cnt_outros=!_cnt_outros! + 1 copy "%%~f" "%userprofile%\Desktop\Nova pasta (2)\" /v /y >nul 2>nul ) echo. && echo/ COPIANDO ARQUIVOS JPEG... set /a _cnt_total=!_cnt_jpg! + !_cnt_outros! set "_show_cnt_jpg=000000!_cnt_jpg!"&& echo/ Arquivos .jpgs copiados: !_show_cnt_jpg:~-7! set "_show_cnt_outros=000000!_cnt_outros!"&& echo/ Arquivos n jpg copiados: !_show_cnt_outros:~-7! Echo/ -------------------------------- set "_show_cnt_total=000000!_cnt_total!"&& echo/ Totalizado jpg + outros: !_show_cnt_total:~-7! )     
02.12.2018 / 22:08