Community
    • 登入

    Open two files side by side from command line

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    7 貼文 3 Posters 1.5k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • MMMZZZZM
      MMMZZZZ
      最後由 編輯

      Hi everyone,

      I’d like to do what the title says: create one .cmd file that’ll fire up Notepad++ and show me the two files side by side. I have checked the CLI reference and can see how to open two files via command line but I couldn’t see how to do the side-by-side thing.

      The purpose is this: I have created a python script that compares a lot of different text files. Interesting file pairs that need closer investigation are put into separate folders for easy navigation. This works great but I still need to open every file pair and drag them around inside of Notepad++. I’d like to automatically create a .cmd file for each pair that’ll immediately open the files side-by-side and thus reducing the amount of repetitive clicking around.

      Thanks in advance!
      Max

      Alan KilbornA 1 條回覆 最後回覆 回覆 引用 0
      • Alan KilbornA
        Alan Kilborn @MMMZZZZ
        最後由 Alan Kilborn 編輯

        @MMMZZZZ

        If you’re a Pythoner, doing this using the PythonScript plugin should be fairly easy.
        Do you want to take a look at doing that all by yourself, or do you want some guidance?

        Since you mentioned comparing, you may take a look at the Compare plugin.
        Since I don’t use it, I can’t advise any further on if it can auto-open two files passed in on N++ startup (I doubt it, though).

        1 條回覆 最後回覆 回覆 引用 0
        • MMMZZZZM
          MMMZZZZ
          最後由 編輯

          Thank you for the quick reply!

          I did find that plugin but there are 2 issues:

          • I’m not the only one who’ll use this script and I’d prefer solutions that work “out of the box” without extra plugins to install. If it’s not possible without those, okay, better than nothing, but IMO for this case it’s the second choice
          • PythonScript seems to be based on Python 2 which I don’t have installed, never used and honestly didn’t plan to learn/use since it’s deprecated. There is a Python 3 version in development but if I understand the release notes correctly it doesn’t work for non-unicode files (which I have to deal with). I haven’t looked any deeper into this; maybe there’s a workaround for that…

          If you got any other ideas I’d be very thankful! Otherwise I guess I’ll have to try with PythonScript…

          Kind regards,
          Max

          1 條回覆 最後回覆 回覆 引用 0
          • EkopalypseE
            Ekopalypse
            最後由 編輯

            @MMMZZZZ

            just for the record, pythonscript comes with python dll so there is no need to install anything other than the plugin itself.

            Without plugins, the only possible solution I can think of is to create a session file, created by a batch or your python script, and then start npp with the -openSession parameter and the previously created session file.

            MMMZZZZM 1 條回覆 最後回覆 回覆 引用 2
            • MMMZZZZM
              MMMZZZZ @Ekopalypse
              最後由 編輯

              @Ekopalypse I played a bit with the sessions file and the command line options. I don’t fully understand the behavior but I got something that works. Thanks a lot!

              Max

              1 條回覆 最後回覆 回覆 引用 1
              • MMMZZZZM
                MMMZZZZ
                最後由 MMMZZZZ 編輯

                Oh lord the encodings are killing me…

                Filepaths in the session.xml file somehow need to escape characters even though cp1252 and UTF-8 are well capable of encoding them directly (f.ex. ü)… Then the python xmlcharrefreplace option encodes them with decimal number (ü) instead of hex (&#00FC) - which notepad++ won’t accept. And finally, the CLI option -ope1nSession doesn’t seem to handle filepaths with any of the versions above.

                To make things even better, if anything of all the above doesn’t work, notepad++ doesn’t give you any hint. it just opens a blank new file. I couldn’t find any --verbose option for the CLI either.

                Help would be appreciated before I go insane…

                Max

                EkopalypseE 1 條回覆 最後回覆 回覆 引用 0
                • EkopalypseE
                  Ekopalypse @MMMZZZZ
                  最後由 Ekopalypse 編輯

                  @MMMZZZZ said in Open two files side by side from command line:

                  ü

                  not 100% sure what the issue is. The generation of the session file or opening the sessions with npp?

                  What I did is the following:

                  a) created a file D:\über.txt
                  b) created a file D:\temp\ökonmische betrachtung\ärger.txt
                  c) moved the second file to the second view
                  d) used File->SaveSession and saved it as D:\test_session.xml
                  e) open a cmd and started D:\Tests\npp\810\x64\notepad++.exe -openSession D:\test_session.xml

                  resulted in

                  613d2d9c-ef38-44cc-b59f-2f38573a23e7-image.png

                  To reuse this mechanism, I would modify the session.xml file and replace the two filename tags with something unique like %%FILE1%% and %%FILE2%% and then have my script replace them with the real name of the file, making sure they are xml encoded.
                  As a template, of course. The script would create the real session file.

                  1 條回覆 最後回覆 回覆 引用 3
                  • 第一個貼文
                    最後的貼文
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors