jackr57 Posted December 10, 2015 Share Posted December 10, 2015 (edited) HiI have a working outlook signature script, that pulls data from active directory. I am just having a problem with fields that are optional. Func regsig () FileInstall("sig.htm", $sigpath & "\tmp.htm",1) $filename1 = $sigpath & "\tmp.htm" _ReplaceStringInFile($filename1,"namenamename",$fullname) _ReplaceStringInFile($filename1,"emailemailemail","<a href='mailto:"& $emailaddress &"'>" & $emailaddress & "</a>") _ReplaceStringInFile($filename1,"titletitletitle",$title) _ReplaceStringInFile($filename1,"offnumoffnumoffnum",$officenumber) _ReplaceStringInFile($filename1,"faxfaxfax",$faxnumber) _ReplaceStringInFile($filename1,"extensionAttribute1extensionAttribute1extensionAttribute1",$extensionAttribute1) If $mobilenumber <>"" Then _ReplaceStringInFile($filename1,"mobilemobilemobile", "Mobile: " & $mobilenumber) Else _FileWriteToLine($filename1, 13, "", 1) EndIf If $mainnumber <>"" Then _ReplaceStringInFile($filename1,"mobile2mobile2mobile2", "Mobile: " & $mainnumber) Else _FileWriteToLine($filename1, 14, "", 1) EndIf If $webpage <>"" Then _ReplaceStringInFile($filename1,"webpagewebpagewebpage","<a href='"& $webpage &"'>" & $webpage & "</a>") Else _FileWriteToLine($filename1, 16, "", 1) EndIf FileCopy($filename1,$sigpath & "\" & $sightm,1) EndFuncAs you can see here_FileWriteToLine($filename1, 13, "", 1)This works great but the problem is that the line numbers change when certain fields are removed preventing this line removal method from working.If the fields in AD are blank and the else statement is not there, then it simply writes "mobilemobilemobile" to the line as that is what it is in the template file. Ideally I would need a way to use _replacestringinfile in such a way that removes the line when the active directory field that is mapped to that variable is empty.Else _ReplaceStringInFile($filename1,"mobile2mobile2mobile2","")This results in an empty line in the signature which is better than mobile2mobile2mobile2. but ideally would like to remove the line. Edited December 10, 2015 by jackr57 Link to comment Share on other sites More sharing options...
Jury Posted December 10, 2015 Share Posted December 10, 2015 (edited) I'm I missing something or can't you just use StringRegExpReplace and include the line return, new line in the pattern to be replaced?Else $filename1 = StringRegExpReplace($filename1, '(?i)(?-s)mobilemobilemobile\s*', '') EndIf Edited December 10, 2015 by Jury Link to comment Share on other sites More sharing options...
Belini Posted December 10, 2015 Share Posted December 10, 2015 I also could not remove empty lines but you can create a new one without them.#include <File.au3> $original_file = @ScriptDir & "\test.ini" $new_file = @ScriptDir & "\test new.ini" $count_line = _FileCountLines($original_file) For $i = 1 To $count_line $text = FileReadLine($original_file, $i) If $text <> "" Then FileWriteLine($new_file, $text) Next My Codes: Virtual Key Code UDF: http://www.autoitscript.com/forum/topic/138246-virtual-key-code-udf/ GuiSplashTextOn.au3: http://www.autoitscript.com/forum/topic/143542-guisplashtexton-udf/ Menu versions of Autoit: http://www.autoitscript.com/forum/topic/137435-menu-versions-of-autoit/#entry962011 Selects first folder of letters: ]http://www.autoitscript.com/forum/topic/144780-select-folders-by-letter/#entry1021708/spoiler] List files and folders with long addresses.: http://www.autoitscript.com/forum/topic/144910-list-files-and-folders-with-long-addresses/#entry102 2926 Program JUKEBOX made in Autoit:some functions:http://www.youtube.com/watch?v=WJ2tC2fD5Qs Navigation to search:http://www.youtube.com/watch?v=lblwOFIbgtQ Link to comment Share on other sites More sharing options...
jackr57 Posted December 10, 2015 Author Share Posted December 10, 2015 Thanks for the suggestions. I realized while using the second solution that I can just remove the <br /> in the html as its html signature and this will remove the lines._ReplaceStringInFile($filename1,"mobile2mobile2mobile2<br />", "")For text signature i can use the code:$original_file = $filename1 $new_file = $sigpath & "\" & $sightm $count_line = _FileCountLines($original_file) For $i = 1 To $count_line $text = FileReadLine($original_file, $i) If $text <> "" Then FileWriteLine($new_file, $text) NextUnfortunately for the rtf signature there is no solution but no one uses rtf so they will have to put up with blank lines on that one or purchase some signature software. Thanks again for your help. 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