Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating Comma-Delimited Files without Quotation Marks
Message
 
 
À
15/06/2000 15:30:20
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00380950
Message ID:
00381369
Vues:
21
>I have been striving to create a comma-delimited file that does not put double quotes around the text fields from a cursor in FoxPro. I don't want anything that identifies whether the field is character or numeric. I watched someone do it once with the COPY TO command (which is what I intend to use), but I have misplaced my notes of the syntax.

Hi John,

Just about month ago we found the same problem. This is an our solution. (BTW, instead of cursor part you can use strtofile() and filetostr() as Robert suggested)
*--------------------------------------------------------------------------
* -- Calculate the list of txt file names from the cdbfname (ojc.outtable)
*--------------------------------------------------------------------------
lcPath=justpath(cdbfname)+'\'
lnPos=rat('\',cdbfname)
lcPattern=left(cdbfname,lnPos+1)+'???'+substr(cdbfname,lnPos+4)
lcPattern=forceext(lcPattern,'txt')

lntxtfiles=adir(laTxtFiles, lcPattern) && Retrieve list of text files

*--------------------------------------------------------------------------
* -- loop through the array and perform string transformations in each text file
*--------------------------------------------------------------------------
create cursor lcTempCursor ;
     (WorkField M)
append blank

for i=1 to lntxtfiles

     lcFileName=lcPath+laTxtFiles[i,1]
     lnFileSize=laTxtFiles[i,2] && File Size
     lcSendFileName = lcPath+lcCurState+'\'+left(laTxtFiles[i,1],4)+'.txt'
     wait window nowait 'Preparing file '+lcSendFileName
     if file(lcSendFileName)
          erase (lcSendFileName)
     endif

     if lnFileSize< 5000000 && Relatively small files

          append memo WorkField from (lcFileName) overwrite
          if !empty(alltrim(WorkField))
               replace WorkField with strtran(WorkField,'"','')
               copy memo WorkField to (lcSendFileName)
          endif

     else && For huge files this technique doesn't work, let's try something different
          wait window nowait 'Preparing big file '+lcSendFileName+;
               chr(13)+'Size '+alltrim(str(round(lnFileSize/1024,0)))+' KB'+ ;
               chr(13)+'Please, wait...'

          local inFile, outFile, lcBuffer     

          inFile= fopen(lcFileName) && Open a file
          outFile=fcreate(lcSendFileName) && Create a file

          do while !feof(inFile)
               lcBuffer=fgets(inFile,1000) && Get the string
               lcBuffer= strtran (lcBuffer,'"','')
               =fputs(outFile,lcBuffer)
          enddo

          =fclose(inFile)        && Close In file
          =fclose(outFile)       && Close Out file

     endif

next
use in lcTempCursor

select (lnSelect)
HTH
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform