Page 1 of 1

What is wrong in this code ????

Posted: 13 Nov 2011 03:12
by dostips12
i have problem in this code
xcopy works fine but when add ELSE dont work
why that?

@echo off & setLocal EnableDELAYedeXpansion
for /f "tokens=* delims= " %%a in ('dir /s /b/a-d "c:\windows\temp2\"') do (
if not exist "c:\windows\temp\%%~nxa" xcopy "%%~pnxa" "c:\windows\temp\
goto bb
ELSE (GOTO start1)
)
:bb
echo no need to copy
ping -n 5 localhost> nul
exit

:start1
echo finish copy
ping -n 10 localhost> nul
exit

thanks in advance.

Re: What is wrong in this code ????

Posted: 13 Nov 2011 03:22
by Ed Dyreen
'
Untested !

Code: Select all

@echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in (

   'dir /s /b/a-d "c:\windows\temp2\"'

) do if not exist "c:\windows\temp\%%~nxa" (
      ::
      xcopy "%%~pnxa" "c:\windows\temp\"
      goto :bb "()"
) ELSE GOTO :start1 "()"

:bb ()
::(
   echo.no need to copy
   ping -n 5 localhost> nul
::)
exit /b 0

:start1 ()
::(
   echo.finish copy
   ping -n 10 localhost> nul
::)
exit /b 0
This is just a little better, it can be much better, this way you'll understand though.
You made several mistakes like forgetting to add a quote, telling CMD to close the DOS session with exit instead of closing only the function etc..

try this:

Code: Select all

@echo off
call /? |more
exit /? |more
for /? |more
if /? |more

Re: What is wrong in this code ????

Posted: 13 Nov 2011 03:44
by dostips12
Thank u for your great reply

but still alittle problem

the purpose of this code to compare two folders

but when i add new file or more the code do not copy them and move to :start1 () although there is differnt between two folders

thanks