What is wrong in this code ????

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
dostips12
Posts: 5
Joined: 29 Sep 2011 04:03

What is wrong in this code ????

#1 Post by dostips12 » 13 Nov 2011 03:12

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.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

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

#2 Post by Ed Dyreen » 13 Nov 2011 03:22

'
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

dostips12
Posts: 5
Joined: 29 Sep 2011 04:03

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

#3 Post by dostips12 » 13 Nov 2011 03:44

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

Post Reply