Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Opening all dbfs in a directory
Message
De
18/10/2013 13:28:38
Mike Yearwood
Toronto, Ontario, Canada
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01585571
Message ID:
01585835
Vues:
84
Hi Colin

Just so you know, the code you have below is not Craig's code. A much cleaner and simpler version of the code is this: That is because it does not use public variables, it does not use 2 arrays and it does not use macro substitution.
* Loop through current folder to find bad dbf
* files by trying to open each. Log failures.
CLEAR
LOCAL lnBadCount, lcTable, loError
lnBadCount = 0
*Grabs first DBF
lcTable = SYS(2000,"*.DBF")
DO WHILE NOT m.lcTable == ""
  TRY
    USE (m.lcTable) IN 0 ALIAS thisDbf
    USE IN SELECT("thisDbf")
  CATCH TO loError
    ? "Table " + m.lcTable + " is bad."
    lnBadCount = m.lnBadCount + 1
  ENDTRY
  *Grabs NEXT DBF
  lcTable = SYS(2000,"*.DBF",1)
ENDDO
* Tell the user how it went
? IIF(m.lnBadCount = 0, "No errors.", TRANSFORM(m.lnBadCount) + " table(s) could not be opened.")
>>Borislav gave you the code.
>>
>>Keep in mind that this will not guarantee the file is not corrupt. It will simply tell you if it can be opened.
>
>That is exactly what i wanted it to do - it enables me to spot the corrupt tables and replace them from a backup
>
>Thanks for your help
>
>>
>>
>>>This is my code - it opens the first database and then errors trying to get the second with Funcion argument value type or count is invalid - I must be missing something very obvious
>>>
>>>CLEAR
>>>CLEAR ALL
>>>SET EXACT ON
>>>SET TALK off
>>>SET DEFAULT TO c:\global
>>>PUBLIC dbfs,cta
>>>DIMENSION dbfs(1000)
>>>DIMENSION gadatabase(1000)
>>>gadatabase=""
>>>
>>>
>>>gnDbcnumber = ADIR(gaDatabase, '*.DBF') && Create array
>>>FOR nCount = 1 TO gnDbcnumber && Loop for number of databases
>>>dbfs(ncount)=gadatabase(ncount,1)
>>>ENDFOR
>>>
>>>
>>>STORE ncount TO cta
>>>
>>>DIMENSION dbfs(cta)
>>>
>>>
>>>FOR xxxx=1 TO cta
>>>STORE ALLTRIM(dbfs,xxxx) TO tablex
>>>tablex=ALLTRIM(tablex)
>>>USE &tablex IN 0 SHARED
>>>next
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform