Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Packing and Re-indexing tables form a form
Message
De
27/04/2007 22:03:23
Neil Mc Donald
Cencom Systems P/L
The Sun, Australie
 
 
À
27/04/2007 16:15:32
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
01220603
Message ID:
01220733
Vues:
21
Hi,
Try something like this. Not fully tested.
SET STEP ON 
SET EXCLUSIVE ON

LOCAL laFiles, lnNoDBFFiles, lnNoCDXFiles, y, x

lcDataLoc="c:\your_data_directory"

DIMENSION laDBFFiles(1,5)
lnNoDBFFiles = ADIR(laDBFFiles,lcDataLoc+"\"+"*.DBF")
=ASORT(laDBFFiles,1)

DIMENSION laCDXFiles(1,5)
lnNoCDXFiles = ADIR(laCDXFiles,lcDataLoc+"\"+"*.CDX")

Dimension laFiles(lnNoDBFFiles,6)
x=1
For x =1 To lnNoDBFFiles
   y=1
   For y = 1 To 2
      laFiles(x,y)=laDBFFiles(x,y)
   Endfor
   lnElement = Ascan(laCDXFiles,Juststem(laDBFFiles(x,1))+".CDX")
   If lnElement>0
      laFiles(x,3)=laCDXFiles(lnElement+1)
   Else
      laFiles(x,3)=0
   Endif
Endfor

* Pack Files
x=1
For x = 1 To lnnodbffiles
   Wait Window "Packing "+lafiles(x,1)+ " ... Please wait" Nowait
   Try
      Use lcdataloc+"\"+(lafiles(x,1)) In 0 Exclusive
      Pack
      Use
       laFiles(x,5)=.T. && Set the array indicating that the file has been Packed
   CATCH
   
   Endtry
   Wait Clear
Endfor

* Reindex Files
x=1
For x = 1 To lnnodbffiles
   If lafiles(x,3)>0 && Do only if CDX size > 0
      Wait Window "Reindexing "+lafiles(x,1)+ " ... Please wait" Nowait
      Try
         Use lcdataloc+"\"+(lafiles(x,1))
         Copy Structure To lcdataloc+"\x.dbf" With Cdx
         Use In (lafiles(x,1))
         Copy File lcdataloc+"\x.cdx" To lcdataloc+"\"+Juststem((lafiles(x,1)))+".cdx"
         Use lcdataloc+"\"+(lafiles(x,1)) In 0 Exclusive

         Reindex

         Delete File lcdataloc+"\x.*"
         laFiles(x,6)=.T. && Set the array indicating that the file has been Reindexed
     Catch

      Endtry
      Use
      Wait Clear
   Endif
Endfor

lnNoCDXFiles = ADIR(laCDXFiles,lcDataLoc+"\"+"*.CDX")

x=1
For x =1 To lnNoDBFFiles
   lnElement = Ascan(laCDXFiles,Juststem(laDBFFiles(x,1))+".CDX")
   If lnElement>0
      laFiles(x,4)=laCDXFiles(lnElement+1)
   Else
      laFiles(x,4)=0
   Endif

Endfor

SET EXCLUSIVE OFF
>I would like to have a form which re-indexes tables and/or packs then. This is a single user system so I can get the files in EXCLUSIVE mode for the pack command. What I am not sure off is what the best method is to re-index the tables. What is the best way of determining the existing indexes and re-creating them.
>
>The reason I need to do is is to remove deleted records.
>
>I do a search but could not find what I needed.
>
>TIA
Regards N Mc Donald
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform