.KEY FROM/A,IDXNAME/A,TO/A
.BRA [
.KET ]

failat 50

if NOT EXISTS [TO]
  makedir [TO]
endif

echo >t:copyindex.cd NOLINE "cd "
cd >>t:copyindex.cd
cd [FROM]

list #? dirs lformat "makedir >nil: [TO]/%n" to t:copyindex.tmp
execute t:copyindex.tmp

list #?/[IDXNAME] lformat "copy %p%n TO [TO]/%p%n" to t:copyindex.tmp
execute t:copyindex.tmp

delete >nil: t:copyindex.tmp

execute t:copyindex.cd
delete >nil: t:copyindex.cd
