help with btm fragment

May 12, 2014
18
0
Kansas
I'm running TCMD/TCC 12.11 x64 and have the following batch fragment:
Code:
@echo off
setlocal
set RESTOREDATE=1GE140513
set CASECODE=16
set CC=\0016
set CTRM=1GE
set YY=14
set MM=05
set DD=13
set NODE=1
set DAUDIO="G:\DAUDIO\1\1GE14\0513*"
set OFFSET=-12
iff %@len[%@EXPAND[%DAUDIO]] EQ 0 then
  echo.
  echo `  `No hearings found for 20%YY/%MM/%DD in courtroom %CTRM
  echo.
else
  iff "%PROG" EQ "CourtABLE" then
    set OFFSET=-24
  else
    set OFFSET=-12
  endiff
  for %SRC in (%@EXPAND[%DAUDIO]) do (
    echo.
    iff isdir %SRC%%CC then
      set DEST=C:\DAUDIO\%NODE\%@RIGHT[%OFFSET,%SRC]%CC
      if not isdir %DEST md /s /n %DEST
      echo `  `Restoring %@RIGHT[%OFFSET,%SRC]%CC, please wait...
      start /wait robocopy %SRC%%CC %DEST /e /z /is /it /r:0 /w:0 /copy:DAT
    else
      echo `  `Case code %@RIGHT[-1,%CC] not found for %@RIGHT[%OFFSET,%SRC] in courtroom %CTRM
    endiff
  )
  echo done.
  echo.
endiff
endlocal
The variables are all set prior in the batch file. I just specifically defined them here for testing. The issue I'm having is that if %DEST (C:\DAUDIO\1\1GE14\05130903.28\0016) already exists, it completely skips the "echo Restoring" and robocopy lines and just displays "Done." If %DEST doesn't exist, it creates it and copies correctly.

I don't have anything in there telling it to skip if it already exists so I'm confused. If I tell it to delete %DEST then it copies correctly every time. Also, if I remove the "if not isdir %DEST md /s /n %DEST" line then it echos the "Restoring" line but still doesn't run the robocopy.
Any ideas on this would be helpful. The goal is it should run robocopy every time regardless of whether or not the destination folder already exists.
 
Jun 2, 2008
359
4
You have an uneven number of IF/IFFs and ELSEs. I think your last ELSE is being used for your IF instead of the IFF you're expecting it to.
 
May 12, 2014
18
0
Kansas
@Charles Dye - DUPLICATEBUGS=Yes. I changed it to No and it now works as expected. How would I rewrite that as DO? I've played with DO in the past on other projects but could never get it to work as expected whereas FOR always has.

@TEA-Time - IF doesn't use ELSE, only IFF so I don't think that's the issue.

EDIT: OK, in cmd.exe IF uses ELSE so you may be right, @TEA-Time since I had duplicatebugs enabled. :)
 
Jun 2, 2008
359
4
You might want to look at the help for IF.

"The IF ... ELSE ...syntax of CMDis also supported"
 
May 12, 2014
18
0
Kansas
You might want to look at the help for IF.

"The IF ... ELSE ...syntax of CMDis also supported"
Yes, I realized that right after I replied and added the edit to my post. :)
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,461
88
Albuquerque, NM
prospero.unm.edu
@Charles Dye - DUPLICATEBUGS=Yes. I changed it to No and it now works as expected. How would I rewrite that as DO? I've played with DO in the past on other projects but could never get it to work as expected whereas FOR always has.

I think you'd just change the FOR line to DO SRC IN %DAUDIO, and replace the closing parenthesis with an ENDDO. (Those parentheses are your problem, since they smash everything between them onto a single line.) You may also need to think about quoting, if any of your filenames contain spaces.
 
May 20, 2008
11,400
99
Syracuse, NY, USA
The structure of it seems OK. This works (below) correctly with v12 (32-bit). That is, I see "4" and "5" regardless of whether v:\zzz exists or not.
Code:
@echo off
setlocal
iff 1 == 2 then
   echo 1 == 2
else
   iff 2 == 2 then
     echo 2 == 2
   else
     echo 2 != 2
   endiff
   for /l %i in (1,1,3) do (
     iff isdir c:\windows then
       echo 3
       if not isdir v:\zzz md /s /n v:\zzz
       echo 4
       echo 5
     else
       echo 6
     endiff
   )
endiff
 
May 12, 2014
18
0
Kansas
OK, I changed the FOR loop to DO and it seems to run correctly whether OPTION DUPLICATEBUGS is yes or no so apparently it's a bug in how cmd.exe handles FOR. Thanks for the suggestions, Charles.
 
Similar threads
Thread starter Title Forum Replies Date
C Cmpr_Del.btm need help understanding UDF..... Support 2
C Add link to ewriter help to program group... Support 3
samintz How to? Search for %(command) in Help? Support 1
Joe Caverly Favorites in eWriter Help Support 6
Joe Caverly Quick Search in eWriter Help Support 1
vefatica Online help? Support 2
fishman@panix.com HELP!! I just updated to Version 28 and as usual I cannot make extended directory search work. Support 2
JohnQSmith New online help file wrong logo Support 7
Jay Sage Documentation Function @DRIVE Missing in Help Lists Support 0
Charles Dye More help nits Support 0
D Documentation Typo in COPY help Support 0
FreezerBurnt Help making a CMD and TCC compatible batch file Support 7
Joe Caverly Documentation COMMANDS in Version 27 help Support 8
K_Meinhard How to? Help window position Support 7
U Command help on file names Support 5
D Documentation Help "Startup" page does not describe global lists Support 0
vefatica Help disappears? Support 6
rchapmanitt Help Purchasing Support 2
Charles Dye Documentation Help nits: @ZIPFILECRC Support 0
C version help Support 3
C Documentation Help Nit. REN / RENAME Support 0
Dmitry L. Kobyakov Documentation Error in the Help: the WINDOW command Support 0
vefatica Help for @PID Support 2
vefatica Need help with XML Support 3
Alpengreis Documentation Minor issue in help file for view /E Support 1
R Documentation Advanced Directives Help Support 0
R Documentation Help Nit with SETP Support 0
R wmic command help Support 9
R Documentation Help Nit > bdebugger View Menu Support 0
R Documentation A couple of Help nits Support 0
R Documentation Help typo Support 1
MikeBaas How to? I need help with RD Support 5
R Documentation v25 Help Comments Support 1
Joe Caverly DIRectory Colorization in v25 Help File Support 0
vefatica Help nit Support 0
D error in help documentation? Support 0
Joe Caverly _EXPANSION in help file Support 0
K_Meinhard Help file error Support 1
Joe Caverly JOBMONITOR in Help File Support 1
A Documentation [Help file] OPTION "//" synopsis formatting issue Support 0
D The local HELP viewer... Support 0
Chen Touboul Overtyping issue - i press the Insert key, help till press enter for new line in TCC Support 2
C Documentation Help nix ZIP /M Support 0
Joe Caverly v24 Help File - DATEMONITOR Support 1
Joe Caverly 7zip command links to zip help Support 0
K_Meinhard Help problems Support 3
Charles Dye Documentation Help Nits Forever: Checksum functions Support 0
Joe Caverly SAVECONSOLE in Help File Support 0
Joe Caverly CMDebug v23 Help: /FEEDBACK /UPDATE Support 0
Joe Caverly CMDebug v23 Help: Link to MOUNTVHD goes to MOUNTISO in UNMOUNTVHD Support 0

Similar threads