how to stop macro from changing folders

how to stop macro from changing folders

3
NewbieNewbie
3

    Feb 20, 2006#1

    UltraEdit v10

    My simple macro to open a file and goto the bottom works fine.

    Unfortunately it changes the folder I was previously working in to the folder where the file is located that I used the macro to open.

    How can either stop the macro from changing the original folder OR at the end of the macro, restore the original folder??

    TIA
    Nerd2

    6,675585
    Grand MasterGrand Master
    6,675585

      Feb 20, 2006#2

      The macro does not change the current working directory. This is normal for every file open. It will also happen if you open a file without macro.

      For file open (and only for file open - not for example for Find In Files in current working directory) there are settings to specifiy which directory should be file open directory.

      See the options:

      Use default directory from shortcut on initial file open

      Use active file directory for file open dialog default

      See help of UltraEdit for details about these 2 options. For v10 of UE the settings should be anywhere in the General configuration page.
      Best regards from an UC/UE/UES for Windows user from Austria

      3
      NewbieNewbie
      3

        Feb 21, 2006#3

        No, I don't think you understood.

        My macro opens a file in a folder other than the one I was in when I ran the macro. After the macro, and going to File open, I
        find I am in the folder where the macro opened the file.

        I found a kludge fix.

        I end the macro with an Open "x" which of course errors out with a popup message BUT, the folder is still where I was originally.

        Now if only there were a way to kill the error message.....

        Ciao

        344
        MasterMaster
        344

          Feb 21, 2006#4

          Hi Nerd,

          You are right and wrong...

          1st, you seem to have the configuration "Use active file directory for file open dialog default".

          Try this:
          Close all
          Open a file, say c:\test.txt
          open "open file dialog" again: c:\ is "default directory". Press cancel.
          run your macro. it opens a 2nd file, say: d:\second.txt
          open "open file dialog" again: d: sould be the dir.
          NOW CHOOSE THE TAB OF THE FIRST FILE
          open "open file dialog" again: now C: should be the dir. Press cancel.
          You see ?

          ry the other setting "Use default directory from shortcut on initial file open" that Mofi explained.

          rds Bego
          Normally using all newest english version incl. each hotfix. Win 10 64 bit

          6,675585
          Grand MasterGrand Master
          6,675585

            Feb 21, 2006#5

            I have understood you. You don't understood how windows applications work.

            Normally if a windows application like UltraEdit opens a file with the File Open command (not drag and drop from Windows Explorer to UltraEdit) the application itself changes the current working directory to the directory where the file is stored. The current working directory FOR THIS APPLICATION is changed, not for any other application. You can't see that change of current working directory except you do following:

            Open a file with File - Open.

            Run Advanced - DOS Command with command dir, nothing entered in the field for working directory and Show DOS Box checked. The DOS command dir is executed and the ouput is captured. At the captured text you will see in the first line, in which directory the dir was executed.

            Close the window with captured text and open a second file with File - Open from a different directory.

            Run again the DOS command dir and you will see at the first line in the captured output that the working directory has changed to the directory of the second file you opened.


            Every application has it's own current working directory. This is a normal behaviour and often wanted. It is also described in the help of Ultraedit at the help topic for the 2 options I posted. Sentence from help: Normally the directory used for the File Open command is the last directory that the editor opened a file from.

            If you open a file with macro command Open you execute File - Open without showing the dialog. But like File - Open the current working directory is changed.

            With Use active file directory for file open dialog default this handling of the current working directory at file open (and only for file open) is overwritten. Now before opening the file open dialog, UltraEdit sets the current working directory to the directory of the file currently active and then opens the file open dialog.

            With Use default directory from shortcut on initial file open the initial file open is done not in the directory of the last recent file saved in the INI but at the directory specified by the field Start In at the properties of the (desktop or start menu) shortcut to UltraEdit. The "Start In" directory is the current working directory at starting a program. Some programs need that the working directory at start is identical with the program directory where the EXE is. So by default the "Start In" directory is set to the program directory during creation of a shortcut.

            But for UltraEdit you can specify a different working directory at start of UltraEdit. With this option enabled, this directory becomes the working directory for initial file open. Initial means that if you start UltraEdit without opening a file (no file is specified at the command line) this directory will be used for the first File - Open. But all following File - Open will use again the directory of the last opened file.


            And what about MS Office applications? They don't use the current working directory for file open and file save but always use the same directory?

            Yes, MS Office is different which I personally hate. It opens and saves new files always from/to a directory specified in the options for every Office application which is by default the "My Documents" directory but can be changed individually for every Office application to a different directory.

            It seems that you want this handling also for UltraEdit. No problem. Turn off the 2 settings described above and open the configuration dialog for the Directories. Specify a Default Save Directory and a Default Open Directory. Now at File - Open the current working directory is always set to the default open directory before showing the open dialog and at File - Save As the the current working directory is always set to the default save directory before showing the save dialog. Now you have exactly the same directory handling as MS Office applications always use.

            But note, the current working directory for DOS commands like dir or Find In Files executed in the Directory .\ still changes after every file open.

            Edit on 2009-08-21: Since UE v12.20 (I think, but I'm not sure about the version) after opening a file with File - Open the current working directory is set always to the UltraEdit program directory. Why? For example some users unpacked an archive to a temp folder and opened one or more of the files in this temp folder in UltraEdit. After reading they closed the files in UltraEdit, but not UltraEdit itself. Next they wanted to delete the temp folder, but since NT4 Windows does not allow deleting a directory used by any application currently as working directory (Win9x does not have this limitation). That's the reason why UE changes the current working directory for itself after File - Open now always to the UE program directory.

            What is the current working directory of an application can be watched for example by using Process Explorer from SysInternals. After starting Process Explorer click with secondary (right) mouse button on a running application and choose Properties. On the Image tab the "Current directory" of the application is displayed.

            344
            MasterMaster
            344

              Feb 21, 2006#6

              Yes, MS Office is different which I personally hate. It opens and saves new files always from/to a directory specified in the options for every Office application which is by default the "My Documents" directory but can be changed individually for every Office application to a different directory.
              UUuuuhhh yes, you're right. :?
              Thats why my "my Documents" - Folder is full of shortcuts to the real places where my data is stored. :wink:
              Alternatively you can determine your "my Document" - Folder to any place you like, e.g. "d:\dat" with Tweak-UI, so that Directory will be your future starting point for Office.
              But after installing Windows for the 10th time, you resign and just do it with a link.....

              rds Bego
              Normally using all newest english version incl. each hotfix. Win 10 64 bit

              3
              NewbieNewbie
              3

                Feb 21, 2006#7

                Ok gentlemen, my error. I did not at first find the checkbox for "Use default directory from shortcut on initial file open". Found it, checked it and now my macro no longer leaves Uedit in the folder of a file it just opened.

                Thanks to all who took time to reply!

                Nerd