mainpath="c:\wfin\main"

pd=open("pdata")
getfirst(pd)
dat=pd["Тек.дата"]
close(pd)

y=num(substr(dat,1,4))
m=num(substr(dat,5,2))
prd=open("period")
getfirst(prd)
findge(prd,2,1,y,m)
getprev(prd)
while bof(prd)=0
  path=prd["Путь"]
  y1=prd["Год"]
  m1=prd["Месяц"]
  if file_exists(path+"\plan.btr")<>0 then
    if file_exists(path+"\pdata.btr")=0 then
       copyfile(mainpath+"\pdata.btr",path+"\pdata.btr")
       copyfile(mainpath+"\pdata.str",path+"\pdata.str")
       aa=substr(getpath,1,4)+substr(str(y1,1,0),3,2)+str(m1,-2,0)
       pd=open(aa+"\pdata")
       getfirst(pd)
       dat1=str(y1,1,0)+str(m1,-2,0)+"01"
       dat1=date_set(dat1,1)
       pd["Тек.дата"]=dat1
       update(pd)
       close(pd)
    end if
  else
    goto 100
  end if
  getprev(prd)
wend
100
close(prd)