Community
    • Login

    Macro not working incrementally in Windows 10/Server 2012

    Scheduled Pinned Locked Moved General Discussion
    3 Posts 2 Posters 1.9k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • David PriceD
      David Price
      last edited by

      I’ve been having issues with some macros only working intermittently since transitioning to Windows 10. I’ve noticed that it’s occurring in Server 2012 as well. I believe I noticed it in the latter versions of Notepad++ (6.9).

      It appears that the issue is occurring when using copy/paste (Ctrl-C/Ctrl-V) in the macro.

      For example, if I have a list of documents with date/time stamps appended to them:

      2016900000011.txt.201610190800
      2016900000012.txt.201610190800
      2016900000013.txt.201610190800
      2016900000014.txt.201610190800
      2016900000015.txt.201610190800

      If I record a macro that cuts the date/time stamp from the end and pastes it to the beginning of the line, I get this:

      201610190800.2016900000011.txt
      201610190800.2016900000012.txt
      2016900000013.txt
      201610190800.2016900000014.txt
      201610190800.2016900000015.txt

      It’s as if it’s losing the copied content in the clipboard at times.

      Anyone else been experiencing this in Windows 10/Server 2012 or in latter versions of Notepad++?

      1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by guy038

        Hello David,

        I can’t offer you any help about Windows 10 / Server 2012 as I, currently work with an old Win XP SP3 version ! Yes, I know, I’m a kind of dinosaur ;-))

        However,for basic changes of text, in a file, as yours, it would be quicker and more powerful to use regular expressions to do the job ! Moreover, the macro creating phase would become useless !


        For instance, once your file is opened in N++, with the cursor located line 1 and column 1 of your list :

        • Open the Find/replace dialog ( Ctrl + H )

        • Type , in the Find What : zone, the regex ^(\h*)(.+)\.(.+)

        • Type, in the Replace with zone, the regex \1\3 \2, with 3 spaces between \3 and \2

        • Select, at the bottom, the Regular expression search mode ( IMPORTANT )

        • Uncheck, if necessary, the . matches new line` option ( IMPORTANT )

        • Finally, click on the Replace All button

        Et voilà ! Done :-)

        So, from your original text, below :

        2016900000011.txt.201610190800
        2016900000012.txt.201610190800
        2016900000013.txt.201610190800
        2016900000014.txt.201610190800
        2016900000015.txt.201610190800
        

        we get the modified text, below :

        201610190800   2016900000011.txt
        201610190800   2016900000012.txt
        201610190800   2016900000013.txt
        201610190800   2016900000014.txt
        201610190800   2016900000015.txt
        

        Now, just imagine that :

        • Your text has leading spaces or tabulations, before the name of the files, like below :

                    2016900000011.txt.201610190800
                    2016900000012.txt.201610190800
            		2016900000013.txt.201610190800
                    2016900000014.txt.201610190800
            		2016900000015.txt.201610190800
          

        with lines 1, 2 and 4 which begin with 12 space characters and lines 3 and 5 which begin with 3 tabulation characters

        • You write, this time, in the Replace with zone, the regex \1\3 is the DATE/TIME stamps of the FILE \2

        Then, after performing this S/R, you should get the text below :

                    201610190800 is the DATE/TIME stamps of the FILE 2016900000011.txt
                    201610190800 is the DATE/TIME stamps of the FILE 2016900000012.txt
        			201610190800 is the DATE/TIME stamps of the FILE 2016900000013.txt
                    201610190800 is the DATE/TIME stamps of the FILE 2016900000014.txt
        			201610190800 is the DATE/TIME stamps of the FILE 2016900000015.txt
        

        Notes, on that second S/R :

        • The first part of the search regex, (\h*), inside round brackets, memorize the leading blank characters, of the current line, as group 1

        • Then, the middle part (.+)\. memorize, as group 2, the complete name of the file, of the current line, as it catches the longest string till the dot character ( located between the names and the date/time stamps ). The dot, itself, must be escaped to be taken literally, as it’s a special symbol, in regular expressions.

        • Finally, the end part (.+) memorize, as group 3, the date/time stamps, of the current line, as it catches all the remaining characters till the EOL characters, excluded

        • The first part of the replacement string \1\3 rewrites the indentation of the current line, followed by the date/time stamps

        • Then, the part is the DATE/TIME stamps of the FILE is simple text to be inserted, with that exact case, after the date/time stamps

        • Finally the part \2 rewrites the name of the current file

        Best Regards

        guy038

        1 Reply Last reply Reply Quote 1
        • David PriceD
          David Price
          last edited by

          Thank you so much guy038.

          I use regex for find/replace frequently, but didn’t consider using it for this. I’m sometimes working with more than 1 million lines of file lists, and macros usually worked well, but regex could produce quicker output results.

          Another time I’d use macros, which I don’t think this regex method will work on, is copying the file’s name into the text.

          For example, if the text is:

          2016900000011.txt.201610190800

          …and the file containing the text is test.txt. Using Edit -> ‘Copy to Clipboard -> Current Filename to Clipboard’ in the macro, the output would be:

          test.txt\2016900000011.txt.201610190800

          I guess I can perhaps try accomplishing this when creating the directory lists from a command line.

          Thanks again for your detailed feedback!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          The Community of users of the Notepad++ text editor.
          Powered by NodeBB | Contributors