xcaliber13 Posted March 28, 2017 Posted March 28, 2017 Good Afternoon, I have been searching the forum for hours and still cannot figure out why this script does not work. No errors but does not replace anything. I have checked my regex with the regex coach. That part at least in The Regex Coach works. Any help please #include <file.au3> #include <Array.au3> #include <String.au3> #include <StringConstants.au3> #include <Date.au3> #include <FileConstants.au3> Global $sPath = "C:\Test" Global $mPath = "C:\PRPATemp" Global $sFolder = _FileListToArray($sPath, Default, $FLTA_FILES) ;ShellExecute("C:\Users\user82.PPMCINC\Desktop\WorkingScripts\PRPAMammoChargeFileMove.vbs") $sfolder = "C:\PRPATemp" $aFileList = _FileListToArray($sfolder, "*", $FLTA_FILES) ;_ArrayDisplay($aFileList) Global $aArray For $i = 1 To $aFileList[0] _FileReadToArray($aFileList[$i], $aArray, 0) StringRegExpReplace($aArray, "QEGTPACS(.*)2\.1", "QEGTPACS.1.1111111|P|2.1") _FileWriteFromArray($aFileList[$i], $aArray) Next
Moderators Melba23 Posted March 28, 2017 Moderators Posted March 28, 2017 xcaliber13, An array cannot be accessed as a single entity by StringRegExpReplace as you try to do in that script. You will either have to convert the array contents to a string and then recreate the array after the manipulation - or loop through each element individually to action the RegEx. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
xcaliber13 Posted March 28, 2017 Author Posted March 28, 2017 Melba23, Thank you for the reply. I started out this way: #include <file.au3> #include <Array.au3> #include <String.au3> #include <StringConstants.au3> #include <Date.au3> #include <FileConstants.au3> Global $sPath = "C:\Test" Global $mPath = "C:\PRPATemp" Global $sFolder = _FileListToArray($sPath, Default, $FLTA_FILES) ;ShellExecute("C:\Users\user82.PPMCINC\Desktop\WorkingScripts\PRPAMammoChargeFileMove.vbs") $sfolder = "C:\PRPATemp" $aFileList = _FileListToArray($sfolder, "*", $FLTA_FILES) ;_ArrayDisplay($aFileList) Global $sFile Global $str For $i = 1 To $aFileList[0] $sFile = FileOpen($aFileList[$i], 2) $str = StringRegExpReplace($sFile, "QEGTPACS(.*)2\.1", "QEGTPACS.1.1111111|P|2.1") FileWrite($sFile, $str) Next But still script completes with no errors and still nothing is replaced. I am stumped or stupid. Where have I gone wrong?
Moderators Melba23 Posted March 28, 2017 Moderators Posted March 28, 2017 (edited) xcaliber13, FileOpen merely opens the file, it does not read it - try using FileRead. M23 Edit: And you will need to append the path to the filenames in the array - or set the $bReturnPath parameter in _FileListToArray to get the full path into the array. You do have a copy of the Help file handy? Edited March 28, 2017 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
xcaliber13 Posted March 30, 2017 Author Posted March 30, 2017 Melba23, Thank you your help. With your directions I was finally able to finish the script. Here is what works for me. #include <file.au3> #include <Array.au3> #include <String.au3> #include <StringConstants.au3> #include <Date.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> ;;This section searchs for QEGTPACS in each file and if found replaces Global $sPath = "C:\PRPATemp\" Global $sFolder = _FileListToArray($sPath, Default, 0, True) ;_ArrayDisplay($sFolder) For $i = 1 to $sFolder[0] Local $sPathAndFileName = $sFolder[$i] Local $sFileOpen = FileOpen($sPathAndFileName) Local $sFileRead = FileRead($sFileOpen) Global $sFile Global $NewFile = $sPathAndFileName &"New" If StringInStr($sFileRead, "QEGTPACS") Then $sFile = StringRegExpReplace($sFileRead, "QEGTPACS(.*)2\.1", "QEGTPACS\.1\.1111111\|P\|2.1", 1) _FileCreate($NewFile) FileWrite($NewFile, $sFile) FileMove($NewFile, "C:\PRPATEMP2") Else ConsoleWrite("Not found in: " & $sPathAndFileName[$i] & @CRLF) EndIf Next Again Thank you for your help
Moderators Melba23 Posted March 30, 2017 Moderators Posted March 30, 2017 xcaliber13, Glad I could help. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now