Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
xhai
- Posts: 39
- Joined: 13 Jun 2013 09:33
#1
Post
by xhai » 30 Aug 2014 02:21
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
-
aGerman
- Expert
- Posts: 4678
- Joined: 22 Jan 2010 18:01
- Location: Germany
#2
Post
by aGerman » 30 Aug 2014 15:32
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
-
xhai
- Posts: 39
- Joined: 13 Jun 2013 09:33
#3
Post
by xhai » 30 Aug 2014 21:49
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