Page 1 of 1

Recursive copy files from folders Part 2

Posted: 30 Aug 2014 02:21
by xhai
Hi guys, a little bit modification of grab2.bat

Code: Select all

@Echo Off & SetLocal EnableExtensions DisableDelayedExpansion
Set _ext=.pdf
PushD %~dp0
For /D %%a In (*) Do If Exist "%%a\*%_ext%" Call :Sub "%%a"
Exit/B

:Sub
Set _cnt=0
For %%a In ("%~1\*%_ext%") Do Set/A _cnt+=1
If %_cnt% NEq 1 GoTo :EOF
If Not Exist "%~1%_ext%" Echo(F|XCopy "%~1\*%_ext%" "%~dp0%~1%_ext%">Nul


./cats/cata/file.bmp
./cats/catb/file.bmp
./cats/catb/file.png
./cats/catb/file.gif
./cats/grab.bat

This time I want grab2.bat to do this loop over the current folders and get all the .png and .gif files from catb folder, copy them and put them in cata folder, E.g (file.bmp, file.png, file.gif) overwrite same file


thank you

Re: Recursive copy files from folders Part 2

Posted: 30 Aug 2014 15:32
by aGerman
Maybe that would do the job.

Code: Select all

@echo off &setlocal
pushd "catb"
for /f "delims=" %%i in ('dir /a-d /b /s *.bmp *.png *.gif') do copy "%%i" "..\cata\"
popd

Regards
aGerman

Re: Recursive copy files from folders Part 2

Posted: 30 Aug 2014 21:49
by xhai
aGerman wrote:Maybe that would do the job.

Code: Select all

@echo off &setlocal
pushd "catb"
for /f "delims=" %%i in ('dir /a-d /b /s *.bmp *.png *.gif') do copy "%%i" "..\cata\"
popd

Regards
aGerman


Thanks aGerman got it work, I've been using CD but I can't make it work on for loop