How to get name of current doc with js?

How to get name of current doc with js?

4
NewbieNewbie
4

    Apr 18, 2007#1

    hello everyone.
    I want to copy the name of active document to a variable as a string, but I find "paste" command just paste it to the file and can not set to a variable. How can I do that?
    I use it like below

    Code: Select all

    UltraEdit.activeDocument.copyFilePath();
    ...
    UltraEdit.activeDocument.paste();
    

    262
    MasterMaster
    262

      Apr 18, 2007#2

      My suggestion is to use the presently undocumented path property:

      Code: Select all

      var filepath = UltraEdit.activeDocument.path;
      

      4
      NewbieNewbie
      4

        Apr 19, 2007#3

        Yeh, it does work. Thanks a lot.
        By the way, I notice that the 'path' command does not list in the help file as someone(sorry, forgot your name),just in the forums, has already pointed out. Are there another unlisted commands?
        Thanks for your reply again.

          Apr 19, 2007#4

          Now, I try this to get the current document name only.

          Code: Select all

          var filepath = UltraEdit.activeDocument.path + "\r\n";
          var i = filepath.lastIndexOf("\\");
          var filename = filepath.slice(i + 1);
          
          And now there is another problem, maybe it is a bug.
          I want to get the current date only. not include the time. So I use below.

          Code: Select all

          var d = new Date();
          UltraEdit.activeDocument.write(d.getFullYear() + "-");
          UltraEdit.activeDocument.write(d.getMonth()  + "-");  \\ note here!
          UltraEdit.activeDocument.write(d.getDate() + "\r\n");
          
          but the result is always less than current month 1 month. I mean now it is Apri, but the answer is March. well I change it to March and get Feb instead. And only getMonth/getUTCMonth works like this.Why?

          344
          MasterMaster
          344

            Apr 19, 2007#5

            I know this behaviour from Perl. You have to add a 1 to the month. Seems a system related issue.
            Maybe s.o. finds an explanation...
            Normally using all newest english version incl. each hotfix. Win 10 64 bit

            262
            MasterMaster
            262

              Apr 19, 2007#6

              No it's not a bug. It's WAD (works as designed) ;-) getMonth() acts like an index for an array and starts with 0 thru 11.

              See more: www.w3schools.com/jsref/jsref_getMonth.asp

              4
              NewbieNewbie
              4

                Apr 20, 2007#7

                Thanks Bego and Jorrasdk.
                Yeh, I completely get it now.
                And Jorrasdk, it is realy very warm-hearted of you for answer my question continously, and give me the related url. It is a realy good website that helps a lot. Thanks again.