replace hexadecimal value by another in dir tree?

  • Thomas

    Thomas - 2013-10-09

    I would like to replace in all *.txt files in a certain directory tree (e.g. D:\aaa\bbb\logs)
    the hexadecimal 2 bytes 'C3B6' by one bytes hex 'f6'

    How can I do this with NP++?

    Is it possible to do this WITHOUT loading all *.txt files into NP++?

    Can I assign this operation to a toolbar icon or menu entry?

    Thank you


    THEVENOT Guy - 2013-10-10

    Hi, Thomas,

    I think that your first two questions are not difficult to solve with N++ :

    • Open the Find in Files dialog with the shortcut CTRL + SHIFT + F

    • In the field Find what type in : \xC3\xB6

    • In the field Replace with type in : \xF6

    • In the field Filters type in : *.txt

    • In the field Directory type D:\aaa\bbb\logs OR click on the square button ..., at right, to select a specific folder

    • Select the radio button Regular expression Search mode ( IMPORTANT )

    • Unset the square box option In all sub-forlders, if necessary

    • Set or Unset the square box Match case, as you like

    • Click on the Replace in Files button

    • Click on the OK button in the confirmation dialog, which pops-up

    Et voilà !!

    As for your third question, I don't think that it's possible to assign your Search/Replacement to a ToolBar icon.

    But the adding of some instructions in the shortcuts.xml file, in Macros's section, to do the job, should be possible :-). I used this method, with my old and last ANSI version of N++ ( 5.9.8 ), to simulate the Clear all marks button, in the fourth tab of the Search dialog, and that worked nice !

    But, at present, it's about 2h00 in France and I'd rather go to bed ! So, if you don't mind, I'll test, this week-end or, maybe, tomorrow, if my solution is still good on the last 6.5 UNICODE version, with Scintilla 3.3.4.

    And, of course, once a macro is created, it's quite easy to assign a shortcut to it !

    See you later,



    Last edit: THEVENOT Guy 2013-10-10

    THEVENOT Guy - 2013-10-13

    Hello Thomas and All,

    If you're interested in coding Search/Replacement macros, directly in the Shorcuts.xml file, go, at once, at the end of this post, to see the general method !

    @ Thomas

    As promised, I'm back to you. Indeed, my previous post was really not complete and wrong, in some parts ! I'm a bit late but I came across some problems !


    I tested the alternative method, relative to shortcuts.xml that I spoke in my last post. It worked fine at the beginning, but all other tests failed afterwards for an unknown reason ! Happily, after one test's day, I understood the the path of files to be changed, written in the new macro of the shorcuts.xml file, must end with an antislash character () !!

    So, with your example, the path will be written D:\aaa\bbb\logs\ in the macro section.


    If, with an other program ( hexadecimal editor, for example ) you create a file ( let say 'Test.txt' ), with the two hex values \xC3\xB6 only, this file, opened in, either Word, classical Notepad or Notepad++, always displays an unique character ö. Why ?

    Just because most of text editors consider every character as part of the UCS ( Universal Character Set ) and use the UTF-8 coding to display all Unicode characters. Now, \xC3\xb6 is , exactly, the UTF-8 coding of the lower case latin letter ö ( of Unicode value \x00F6 )

    So, as the search process use the UTF-8 encoding too, the search expression, in your example, will be \xF6, identical to \x{00f6} ( internally, N++ 'knows' that it corresponds to the UTF-8 encoding ( 2 bytes C3B6 ) of the character ö )


    In your post, you said that your replacement string is the unique byte \xF6. But, in the UTF-8 encoding, the hexadecimal value \xF6 is quite forbidden, as the values \xC1, \xC2 and all values in the range [\xF5-\xFF]. See infos, relative to UTF-8, at the address :

    Then, if you write the value \xF6, as the replacement string, you just overwrite the ö character by itself !!! ( internally, N++ will change the two bytes \xC3\xB6, of the UTF-8 encoding, with these same two bytes ! )


    Of course, if we open again, in Notepad++, the 'Test.txt' file and we select the choice Encoding\Encode in ANSI, it now displays two characters ( ö ) as I use the Windows-1252 ANSI encoding, by default. ( I'm French )

    So, this time, the search, in regular expression mode, of \xC3\xB6 and the replacement with \xF6, do change these two characters in an unique character ! ( the letter ö, with my default Windows-1252 encoding )

    Thus, I still miss some informations about your real needs to give you a better answer !

    @ All,

    To end up, I give you the general method to create a Search ( and Replacement ) macro :-).

    Of course, every specific S/R macro can be affected to a user shortcut. Nice !

    This method was tested with the last 6.5 version of Notepad++.

    • Close any opened instance of Notepad++

    • Open the shortcuts.xml file, with an other editor than N++ ( Notepad, Wordpad, Word...)

    • Inside the Macros section, create a new macro ( which will be activated with the CTRL + F11 shortcut ) :

    <Macro name="Search/Replacement Test" Ctrl="yes" Alt="no" Shift="no" Key="122">

    • Inside this new macro, add the following commands :

    <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />

    This command is mandatory and initialize the Search/Replacement.

    <Action type="3" message="1601" wParam="0" lParam="0" sParam="<u>String to Search</u>" />

    This command is mandatory

    <Action type="3" message="1625" wParam="0" lParam="<u>Search Mode</u>" sParam="0" />

    This command is mandatory and set the Search mode :

    0 = Normal, 1 = Extended and 2 = Regular xpression

    <Action type="3" message="1602" wParam="0" lParam="0" sParam="<u>Replacement String</u>" />

    In case of search only, this command can be absent.

    <Action type="3" message="1653" wParam="0" lParam="0" sParam="<u>Search Path Directory</u>" />

    ( IMPORTANT : the Path must always end with an antislash character(\) )

    This command is necessary in case of Find in files search ( CTRL + SHIFT + F ).

    <Action type="3" message="1652" wParam="0" lParam="0" sParam="<u>File Filters</u>" />

    This command is necessary in case of Find in files search ( CTRL + SHIFT + F ).

    <Action type="3" message="1702" wParam="0" lParam="<u>Options Number</u>" sParam="" />

    This command is mandatory and set the different possible options of the S/R :

    1 Match Whole word only
    2 Match case
    4 Purge for each search
    8 Style found token
    16 Bookmark Line
    32 In all sub-folders
    64 In hidden folders
    128 In selection
    256 Wrap around
    512 Down Direction

    <Action type="3" message="1701" wParam="0" lParam="Command Number" sParam="" />

    This command is mandatory and corresponds to the Search/Replacement type to execute :

    1 Find Next
    1608 Remplace
    1609 Remplace All
    1614 Count
    1615 Mark All
    1635 Replace All in All Opened Documents
    1636 Find All in All Opened Documents
    1641 Find All in Current Document
    1656 Find All
    1660 Replace in Files

    • Open Notepad++ and hit the CTRL + F11 shortcut to execute this pre-defined S/R action.

    Et voila !!!

    Example :

    If, in the directory D:\aaa\bbb\logs, you want to replace every occurrence of the string \x41\x42\x43 ( = ABC ) by the string \x44\x45\x46 ( = DEF ), for all files with *.txt extension, add the following lines to the macro section of the shorcuts.xml file :

    <Macro name="Search/Replacement Test" Ctrl="yes" Alt="no" Shift="no" Key="122">
    <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
    <Action type="3" message="1601" wParam="0" lParam="0" sParam="\x41\x42\x43" />
    <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
    <Action type="3" message="1602" wParam="0" lParam="0" sParam="\x44\x45\x46" />
    <Action type="3" message="1653" wParam="0" lParam="0" sParam="D:\aaa\bbb\logs\" />
    <Action type="3" message="1652" wParam="0" lParam="0" sParam="*.txt" />
    <Action type="3" message="1702" wParam="0" lParam="770" sParam="" />
    <Action type="3" message="1701" wParam="0" lParam="1660" sParam="" />

    Note :

    The number 770 corresponds to the sum :

    512 ( Down Direction ) + 256 ( Wrap around ) + 2 ( Match case )

    Remarks :

    • The Find All in Current Document action ( 1641) doesn't seem to work and is identical to the Find All action ( 1656 )

    • If you use the Count action ( 1614 ), the Search/Replacement dialog must be opened to display the number of the *occurrences, at bottom of the S/R windows.

    See more informations, in the N++_Wiki, at the address below :

    May be, this way to create pre-defined S/R can be useful to someone ?



    Last edit: THEVENOT Guy 2013-10-13
  • Thomas

    Thomas - 2013-10-17

    Hello Guy,
    thank you for your help.

    Two more questions:
    1.) I don't want to fiddle around with editing shortcuts.xml.
    Instead I want NP++ to create the entry. In order to do so I have to proceed as follows.
    - Click menu "Macro-->Start Recording"
    - Click menu "Search-->Find in Files..." and fill in entry fields
    - Click button "Replace in files" and let it run once completely
    - Click menu "Macro-->Stop Recording"

    That will automatically create an apropriate Macro.


    2.) Assume I want to call this Macro the next time NOT from inside NP++ but from a DOS batch script/CmdPrompt. How do I do this? In other words how would the call syntax look like? Something like:

    notepad++.exe -callmacro="myreplmacro123"



    THEVENOT Guy - 2013-10-19

    Hello Thomas,

    Unfortunately, recording S/R actions isn't so simple. In fact, as indicated in the NpWiki++, at the address below :

    it's important to note that ONLY Scintilla actions can be, normally, recorded
    ( roughly, all the actions listed in the Scintilla tab of the Shortcut Mapper + some others in Edit or View menus ! )

    Thus, it almost obvious that Search/Replacement actions are not easily recordable with macro process ( See the end of the article, on NpWiki++ ). That just why, in my precedent post, I gave you a reliable way , but fastidious I admit, to record S/R, in the shortcuts.xml file !

    Many users already asked, in many posts, for such a feature( recordable S/R ), but it would lead to an big project, which is quite over my competences !

    But, an other possibility consists to bookmark some lines and create a macro, containing Scintilla actions ( insertion/suppression of text, cursor's move...), which will be executed, ONLY on the bookmarked lines. Unfortunately, the method, exposed at the end of this article, doesn't work !

    Here is, below, a correct method that I found, after many tries ! ( May be, there's not the only one ! )

    • Suppress all the bookmarks ( Search\Bookmarks\Clear All Bookmarks )

    • Go to the very beginning of the file ( CTRL + Origin )

    • Create a dummy line, at the very beginning of the file ( for example : 40 dashes, followed by ENTER )

    • Go back to the start of this first new line ( CTRL + Origin )

    • Bookmark this new line ( CTRL + F2 )

    • If the macro to execute, has been previously recorded, continue this procedure at mark (A), below

    • START the recording ( Macro\Start Recording ) or the icon with a red circle

    • Go to the next bookmark ( F2 ) ( IMPORTANT )

    ( Note : there's no move at all, because we just are on the only line bookmarked )

    • Execute ALL the Scintilla actions you like, on this dummy line

    • Suppress the bookmark, attached to this dummy line ( CTRL + F2 ) ( IMPORTANT )

    • STOP the recording ( Macro\Stop Recording ) or the icon with a black square

    • Save this macro, if necessary, for future use


    • Bookmark ALL the lines, on whose the macro MUST be executed

    ( You can use either a manual way, ( with mouse clicks or CTRL + F2 ) or an automatic way with the Mark feature of the S/R dialog )


    • Go again to the very beginning of the file, on the dummy line ( CTRL + Origin )

    • Select the option Macro\Run a Macro Multiple Times...

    • Select the wished macro or the choice "Current recorded Macro"

    • Set the "Run until end of file" radio button

    • Click on the "Run" Button ( Et voilà !!! )

    • Hit Echap to close this dialog window

    Then, you can, again, execute the SAME actions of your macro, on OTHER lines. Just, bookmark these lines with the SAME criteria, or, even, with OTHER search criteria and play AGAIN this procedure, from the mark (B), above

    VERY IMPORTANT : The cursor must NEVER be on the FIRST bookmarked line, BEFORE executing the macro !

    • Finally, delete the first dummy line and save your modified current file

    Example :

    Let's suppose you want to SUPPRESS the FIRST and the *LAST character of ANY line, containing the word "feature" in the "change.log" file of the Notepad 6.5 version

    • The dummy line, added at the very beginning of the file, could look like that :

    • The LIST of Scintilla actions, to execute on this dummy line, would be : End, Backspace, Origin, Origin, Suppr ( I wrote Origin action twice, in case a line begins with blank characters )

    Thus, just after the recording, this dummy line consists of dashes only.

    As for your second question, according to what was said above, I think that this new parameter, which doesn't exist yet, would be mainly useful for traditional Scintilla actions, executed on the totality of the lines of files opened.

    Best regards,


    P.S. :

    I just realise that you certainly can, also, achieve automatic search/Remplacements cycles, with the use of a script language, like Python Script. If Dave or Loreia2, two main developers, read this post, they will be able to give you valuable hints about that possibility :-)

    Last edit: THEVENOT Guy 2013-10-19

    THEVENOT Guy - 2013-10-20

    Hi Thomas,

    Of course, my example of Search/Replacement, with a macro and bookmarks, in my previous post, can be easily achieve, with the help of regular expressions :

    • Open the Search / Replacement dialog, with CTRL + H shortcut

    • Set the Regular expression mode

    • Unset the . matches newline option ( IMPORTANT )

    • SEARCH : (?=.*feature).(.+).

    • REPLACE : \1

    • Set/Unset the Match case and Wrap around, as you like

    • Click on the Replace All button

    Notes :

    (?.*feature) is a lookahead which verify that, from the beginning of each line, the string feature exits further, on the current line scanned.

    .(.+). select, if the above condition is true, all characters of each line and split it in 3 parts :

    • The first character
    • All the others, except the last, which are considered as group 1, due to the round brackets
    • The last character

    \1, in replacement part, \1 rewrite all the characters of group 1, of each line

    REMARK :

    I put an + sign, and not a * symbol, in group 1, because each line must contain, at least, the word feature !

    If we add (?-s) at the beginning of the search field, which becomes (?-s)(?=.*feature).(.+). , this forces the option . matches newline to be unset for that present search !



    Last edit: THEVENOT Guy 2013-10-20

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks