Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
OFF TOPIC. Software to replace characters in a file
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Produits tierce partie
Divers
Thread ID:
00042490
Message ID:
00043153
Vues:
36
> Does anybody know a shareware that searches for a string of > characters, in > files in a given directory, and replaces it with another string. If you're a FoxPro bigot, and don't mind waiting for large files, you could use the following untested code: procedure ReplaceTextInAllFiles LParameter lcTextFrom, lcTextTo, lcFileSpec local lnOldSelect, lcThisFile, lnThisFile, lcFileData * Validate the parameters if type("m.lcTextFrom") # "C" or ; empty(m.lcTextFrom) return .f. endif if type("m.lcTextTo") # "C" m.lcTextTo = "" endif if type("m.lcFileSpec") # "C" or ; empty(m.lcFileSpec) m.lcFileSpec = "*.*" endif * Create a temporary cursor m.lnOldSelect = select() select 0 create cursor ReplaceTextInAllFiles (text m) append blank * Loop through the files m.lcThisFile = sys(2000,m.lcFileSpec) do while not empty(m.lcThisFile) * Read in the file append memo text from (m.lcThisFile) overwrite m.lcFileData = ReplateTextInAllFiles.Text * This file has the original text in it. Replace it if len(m.lcFileData) # 0 and ; (m.lcFileData = m.lcTextFrom or ; m.lcTextFrom $ m.lcFileData) * Determine if STRTRAN() or CHRTRAN() should be used if len(m.lcTextFrom) = 1 and ; len(m.lcTextTo) = 1 m.lcFileData = chrtran(m.lcFileData,m.lcTextFrom,m.lcTextTo) else m.lcFileData = strtran(m.lcFileData,m.lcTextFrom,m.lcTextTo) endif * Write out the file m.lnThisFile = fcreate(m.lcThisFile) if m.lnThisFile > 0 =fwrite(m.lnThisFile,m.lcFileData) =fclose(m.lnThisFile) endif endif * Get the Next filename, stopping when finished m.lcThisFile = sys(2000m.lcFileSpec,1) enddo * Close the Cursor use in ReplaceTextInAllFiles select (m.lnOldSelect) return
Paul Russell
EMail: prussell@fox.nstn.ca
Phone: (902) 499-5043
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform