cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

ACL - How to replace all characters provided a file path.

ED_9927023
7-Bedrock

ACL - How to replace all characters provided a file path.

This will be my first script in ACL and I am having struggle finding examples that can be used to understand the language with respect to accessing the filesystem and performing processes on files.

 

No matter what I do - the below code I created and execute multiple times appears to perform different behaviors. Sometimes it has performed a replace on the Currently Open Document in arbortext, sometimes it does nothing, and sometimes it presents a message saying "0 new objects scanned and processed." but have gotten to the point where I know how to create ACL code which won't produce errors. Its just not doing what I think it should.

 

 In my example the ultimate goal will be to replace all Unicode characters (en dash, em dash, curly quotes) with ascii characters (hyphen, straight quotes).

 

$EnDashChr = chr(8211)
$EmDashChr = chr(8212)
$LeftDoubleCurlyQuote = chr(8220)
$RightDoubleCurlyQuote = chr(8221)

 

$filepath = "C:\\Users\\MyDirectory\\Desktop\\TestXML.xml"
$isAccess = access($filepath, "rw")


if ($isAccess = true) {
  message "RW Access TRUE For: $filepath"

  $documentID = doc_open($filepath, 0x80000)
  $currentDocID = current_doc($documentID)

 

  $isEnDashFound = find($EnDashChr, $currentDocID)

  $isEnDashReplaced = replace($EnDashChr, chr(45), 0x2000, $currentDocID)
  $isEmDashReplaced = replace($EmDashChr, chr(45), 0x2000, $currentDocID)

 

  message "[DocID: $currentDocID, EnDashFound: $isEnDashFound, EnDashReplaced: $isReplaced]"

 

  doc_save($currentDocID)
  doc_close($currentDocID)


} else {
  message "RW Access FALSE for: $filepath"
}

 

The way its structured above is to ultimately run a loop on a directory full of xml file paths to batch process. 

 

My question is: What is the correct code flow to perform string manipulation on a file provided a filepath. Am I using the right functions doc_open, doc_save, doc_close to programmatically perform string manipulation on files?

 

Also, i don't see anywhere in the documentation how to "ignore" optional values in a built in functions parameters.

Example: this is replace() in the documentation

replace(searchStr[, replaceStr[, flags[, element[, doc]]]])
But how does one simply ignore the [element] tag such that it essentially will replace in every element.

 

ACCEPTED SOLUTION

Accepted Solutions

The following ACL code works as I'd expect. It replaces instances of "ZZ" with "ZX" in the file at c:\src\test\test1.xml. I just used a blank string to skip the "element" parameter of replace().

$dd = doc_open('c:/src/test/test1.xml')
replace('ZZ', 'ZX', 0x2000, '', $dd)
doc_save($dd)
doc_close($dd)

 

View solution in original post

3 REPLIES 3

The following ACL code works as I'd expect. It replaces instances of "ZZ" with "ZX" in the file at c:\src\test\test1.xml. I just used a blank string to skip the "element" parameter of replace().

$dd = doc_open('c:/src/test/test1.xml')
replace('ZZ', 'ZX', 0x2000, '', $dd)
doc_save($dd)
doc_close($dd)

 

Thank you, this was a perfect example to get me on the right track!

Wonderful! Glad to have helped 🙂

Announcements

Top Tags