kneze Posted April 17, 2018 Share Posted April 17, 2018 Hi script read path to pst files from registry and write this informations to txt file. Unfortunately there are stored not needed lines: path to ost file, other line has string IndexAvailableBodyand first line is blank. How can i remove anything from txt file exept path to pst files ? Thanks in advance! expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <DateTimeConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <array.au3> #include <IE.au3> #include <WinAPIFiles.au3> #include <FileConstants.au3> #include <File.au3> #include <GUIListBox.au3> #include <Date.au3> $Form2 = GUICreate("Form1", 405, 294, 633, 264) $Button1 = GUICtrlCreateButton("Button1", 72, 48, 113, 33) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _searchPSTFiles() EndSwitch WEnd FUNC _searchPSTFiles() Global $aLines ;$sFileName = @ScriptDir & "\Pst.txt" $sFileNameTMP = @ScriptDir & "\Psttmp.txt" ;IF FileExists ($sFileName) then FileDelete ($sFileName) IF FileExists ($sFileNameTMP) then FileDelete ($sFileNameTMP) ;$logpathpst = FileOpen($sFileName, $FO_OVERWRITE) $logpathpsttmp = FileOpen($sFileNameTMP, $FO_OVERWRITE) Local $Outlookpst[30] For $i = 1 To 30 $Outlookpst[$i] = RegEnumVal("HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Search\", $i) If @error <> 0 Then ExitLoop If $Outlookpst = "" Then ContinueLoop EndIf FileWrite($logpathpstTMP, @CRLF & $Outlookpst[$i]) Next ;FileClose ($sFileName) FileClose ($sFileNameTMP) EndFunc Link to comment Share on other sites More sharing options...
Subz Posted April 17, 2018 Share Posted April 17, 2018 Why not just check each entry is: a string contains .pst file exists For example: $i = 1 While 1 $Outlookpst = RegEnumVal("HKCU\Software\Microsoft\Office\16.0\Outlook\Search", $i) If @error Then ExitLoop If $Outlookpst = "" Or FileExists($Outlookpst) = 0 Or StringRight($Outlookpst, 4) <> ".pst" Then $i += 1 ContinueLoop EndIf FileWrite($logpathpstTMP, $Outlookpst & @CRLF) $i += 1 WEnd Link to comment Share on other sites More sharing options...
kneze Posted April 17, 2018 Author Share Posted April 17, 2018 Hi Subz with line If $Outlookpst = "" Or FileExists($Outlookpst) = 0 Or StringRight($Outlookpst, 4) <> ".pst" Then i get no result I use part of your line in my script.WIth for next loop ( line For $j = 2 To $iLinesInFile ) i create new file without first blank line. Thanks for your suggestion. It helped me. expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <DateTimeConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <array.au3> #include <IE.au3> #include <WinAPIFiles.au3> #include <FileConstants.au3> #include <File.au3> #include <GUIListBox.au3> #include <Date.au3> GLOBAL $sFileName = @ScriptDir & "\Pst.txt" GLOBAL $sFileNameTMP = @ScriptDir & "\Psttmp.txt" $Form2 = GUICreate("Form1", 405, 294, 633, 264) $Button1 = GUICtrlCreateButton("Button1", 72, 48, 113, 33) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _searchPSTFiles() EndSwitch WEnd FUNC _searchPSTFiles() IF FileExists ($sFileName) then FileDelete ($sFileName) IF FileExists ($sFileNameTMP) then FileDelete ($sFileNameTMP) $logpathpst = FileOpen($sFileName, $FO_OVERWRITE) $logpathpsttmp = FileOpen($sFileNameTMP, $FO_OVERWRITE) Local $Outlookpst[30] For $i = 1 To 30 $Outlookpst = RegEnumVal("HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Search\", $i) If $Outlookpst = " " Then ContinueLoop If StringRight($Outlookpst, 4) = ".pst" Then FileWrite($logpathpstTMP, @CRLF & $Outlookpst) ContinueLoop EndIf Next $iLinesInFile = _FileCountLines($sFileNameTMP) For $j = 2 To $iLinesInFile $sReadLine = FileReadLine($sFileNameTMP, $j) FileWriteLine($logpathpst, $sReadLine) Next FileClose ($logpathpst) FileClose ($logpathpsttmp) FileDelete ($sFileNameTMP) EndFunc 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