Author Topic: How to open file with macro without file-lock?  (Read 6411 times)

John W.

  • Community Member
  • Posts: 7
  • Hero Points: 0
How to open file with macro without file-lock?
« on: May 22, 2007, 07:44:44 AM »
I've written a macro to open a list-file after I compile a file.
It looks like VS locks the file because I can't recompile the file while the listfile is still opened in VS.
I open the file using "edit_file" as shown below.
I also tried "load_files", but both without success.
If I open the file with "File->Open" there is no problem.
System setting "File locking" is off.

Macro:
_command void FListFileOpen(_str sInFileName='b:\*.lst') name_info(',')
{
   // Find first file
   _str sFileName = file_match(sInFileName,1);

   // Loop to open all .lst files
   for (; ; ) {
              if (sFileName=='' ) break;

              // Open list file in separate buffer
              edit_file(sFileName' -L');

              // Be sure to pass filename with correct path.
              // Result filename is built with path of given file name.
              sFileName= file_match(sInFileName,0);       // find next.
          }
}

Any help would be appreciated.

John Willemsen

StephenW

  • Senior Community Member
  • Posts: 197
  • Hero Points: 21
Re: How to open file with macro without file-lock?
« Reply #1 on: May 23, 2007, 01:08:43 AM »
I do not know if this will help with your problem or not, but you might like to try forcing the files to be opened in read-only mode.  Change the line

    edit_file(sFileName' -L');

to

    edit_file('"-*read_only_mode 1" -L 'sFileName);

I moved the -L to the front of the file name too as all the examples I have seen have it there.

John W.

  • Community Member
  • Posts: 7
  • Hero Points: 0
Re: How to open file with macro without file-lock?
« Reply #2 on: May 23, 2007, 06:19:50 AM »
Thanks,

it looks like I already solved the problem.
I tried the following which seems to work:

_command void FListFileOpen(_str sInFileName='b:\*.lst') name_info(',')
{
   edit (sInFileName);
   return;
}

Don't understand why I didn't try this before  ;)