meows Posted April 20, 2015 Share Posted April 20, 2015 I need to trim the date and accessed times from a file list. It totals 22 spaces need to be trimmed, and I can't seem to get any trimmed. #include <FileConstants.au3> #include <File.au3> #include <MsgBoxConstants.au3> Local $iRead ,$s2String IniRead(@ScriptDir & "\Programsettings.ini", "Filepaths", "SetupDir", $s2String) $iRead=IniRead(@ScriptDir & "\Programsettings.ini", "Filepaths", "SetupDir", "") $sString=$iRead ;MsgBox($MB_SYSTEMMODAL, "", $sString) Local Const $sFilePath = $iRead & "\my.log" ;MsgBox($MB_SYSTEMMODAL, "", $sFilePath) Local $hFileOpen = FileOpen($sFilePath, $FO_READ) Local $sFileRead = FileRead($hFileOpen) ; MsgBox($MB_SYSTEMMODAL, "", $sFileRead) $string_variable = $sFileRead $trimmed = StringTrimLeft ($string_variable, 9) ;Local $sFileRead = StringTrimLeft("",22) MsgBox($MB_SYSTEMMODAL, "", $string_variable) ;;;;;;;;;;;;;;;;;;;;;;;;;("fileList.txt"= $string_variable) ;FileMove ($string_variable,"fileList.txt") ; FileClose($hFileOpen) Exit the file list is attached, I guess if i knew out how to make a file list with out time and date stamps would be easier. Any advice would be of great help. my.7z Link to comment Share on other sites More sharing options...
Solution mikell Posted April 20, 2015 Solution Share Posted April 20, 2015 (edited) ? Local $hFileOpen = FileOpen("my.log", 0) Local $new = "" While 1 $line = FileReadLine($hFileOpen) If @error Then Exitloop $line = StringTrimLeft($line, 22) $new &= $line & @crlf Wend FileClose($hFileOpen) FileWrite("my_new.log", $new) and another way $txt = FileRead("my.log") $new = StringRegExpReplace($txt, '(?m)^.*:\h', "") FileWrite("my_new.log", $new) Edited April 20, 2015 by mikell Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 20, 2015 Moderators Share Posted April 20, 2015 meows,Firstly you are reading the whole file into a single variable, so you would only ever remove the first few characters of the first line - and then you are showing the untrimmed variable in the MsgBox so you never actually see the trimmed version.I suggest reading the file into an array and then trimming each element - something like this:#include <MsgBoxConstants.au3> Local $iRead, $s2String IniRead(@ScriptDir & "\Programsettings.ini", "Filepaths", "SetupDir", $s2String) $iRead = IniRead(@ScriptDir & "\Programsettings.ini", "Filepaths", "SetupDir", @ScriptDir) Local Const $sFilePath = $iRead & "\my.log" Local $aFileRead = FileReadToArray($sFilePath) ; Read into an array For $i = 0 To UBound($aFileRead) - 1 $string_variable = $aFileRead[$i] ; Read each element in turn $trimmed = StringTrimLeft($string_variable, 22) ; Trim it MsgBox($MB_SYSTEMMODAL, "", $trimmed) ; Show trimmed variable and not original Next ExitM23 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 Link to comment Share on other sites More sharing options...
meows Posted April 20, 2015 Author Share Posted April 20, 2015 ? Local $hFileOpen = FileOpen("my.log", 0) Local $new = "" While 1 $line = FileReadLine($hFileOpen) If @error Then Exitloop $line = StringTrimLeft($line, 22) $new &= $line & @crlf Wend FileClose($hFileOpen) FileWrite("my_new.log", $new) and another way $txt = FileRead("my.log") $new = StringRegExpReplace($txt, '(?m)^.*:\h', "") FileWrite("my_new.log", $new) Many thanks.. brain was fried. your a life saver! Link to comment Share on other sites More sharing options...
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