none
can I force files to be closed?

    Question

  • Hi all,

    Is there any way how I can make sure  from VFP that all the files in a specific directory and subdirectories are closed?and if they are not... to force them to get closed?

     

    Sunday, December 12, 2010 12:09 AM

Answers

  • In windows.... if we go to shared files/open files, we can see the files in used and force them to be closed.... is there anyway to reproduce that action from in VFP

    First of all you should keep the directory for development of a foxpro application seperate from the place users run it. Then you wouldn't need to care for backup of exe, prg, scx, frx, etc., just backup the data.

    You can use this code to at least see who has files open: Who-Has-Files-Open

    Bye, Olaf

    • Marked as answer by Liliane Teng Wednesday, December 22, 2010 10:22 AM
    Sunday, December 12, 2010 8:03 PM
  • To allow Admin account privileges just for backup purposes isn't a good approach. Many ways exist to tell the application to close all data files and wait for a certain period of time or until the backup action is finished.

    One of them is a Timer event which checks periodically for the file closing request due to the backup initiated from other workstation. Such request can be a file existence in given folder, DDE message (which does not even need the Timer), some value in shared data table etc.

    The application receiving this request should display a warning and if nothing happens then it can save its environment, close all files and wait for backup action. When it finishes all files can be reopen and app can continue. To close the application when backup request appears is easier, of course.

    The application transmitting the backup request must wait for all files closing, backup files, and remove the backup request when done. If the backup operation cannot run due to some permanently open files then the only possibility is to write this event into a log.

    Another possibility is to backup data from files open by another app instances. Your backup procedure can open data files in shared mode and copy all records into some backup folder and process them as necessary. This backup is slower than operation with exclusive access but you don't need to backup indexes, just DBFs and FPT files. 

    Data integrity is not fully guaranteed when the shared backup reads data written by other app instances but it is surely safer than forced closing of the file open by another user.

     

    • Marked as answer by Liliane Teng Wednesday, December 22, 2010 10:22 AM
    Sunday, December 12, 2010 10:18 PM

All replies

  • See : Close all 
    Sunday, December 12, 2010 5:59 AM
  • You are probably talking about files open by different processes...

    You may try to open them by FOPEN() function - if it fails then some other process has the file open.

    To close such file from VFP application is not simply possible. You would need Administrative rights and some Windows system hook to do it.

     

    Sunday, December 12, 2010 4:04 PM
  • Are you asking about tables or text files?

    And your question is

    1) to force them close from the application that opened them,

    2) to close them by another application (I think it's impossible)

    3) or you just want to know if they are open (accessed by another application) or maybe the same application?

     

    Sunday, December 12, 2010 5:33 PM
  • I have an application and want to make sure I'll be able to make a backup for ALL the files. That include prg, fxp, frx, frt, dbf, cdx, dbc .....

    Also, the files can be in use by any user.

    In windows.... if we go to shared files/open files, we can see the files in used and force them to be closed.... is there anyway to reproduce that action from in VFP

    Sunday, December 12, 2010 7:50 PM
  • In windows.... if we go to shared files/open files, we can see the files in used and force them to be closed.... is there anyway to reproduce that action from in VFP

    First of all you should keep the directory for development of a foxpro application seperate from the place users run it. Then you wouldn't need to care for backup of exe, prg, scx, frx, etc., just backup the data.

    You can use this code to at least see who has files open: Who-Has-Files-Open

    Bye, Olaf

    • Marked as answer by Liliane Teng Wednesday, December 22, 2010 10:22 AM
    Sunday, December 12, 2010 8:03 PM
  • To allow Admin account privileges just for backup purposes isn't a good approach. Many ways exist to tell the application to close all data files and wait for a certain period of time or until the backup action is finished.

    One of them is a Timer event which checks periodically for the file closing request due to the backup initiated from other workstation. Such request can be a file existence in given folder, DDE message (which does not even need the Timer), some value in shared data table etc.

    The application receiving this request should display a warning and if nothing happens then it can save its environment, close all files and wait for backup action. When it finishes all files can be reopen and app can continue. To close the application when backup request appears is easier, of course.

    The application transmitting the backup request must wait for all files closing, backup files, and remove the backup request when done. If the backup operation cannot run due to some permanently open files then the only possibility is to write this event into a log.

    Another possibility is to backup data from files open by another app instances. Your backup procedure can open data files in shared mode and copy all records into some backup folder and process them as necessary. This backup is slower than operation with exclusive access but you don't need to backup indexes, just DBFs and FPT files. 

    Data integrity is not fully guaranteed when the shared backup reads data written by other app instances but it is surely safer than forced closing of the file open by another user.

     

    • Marked as answer by Liliane Teng Wednesday, December 22, 2010 10:22 AM
    Sunday, December 12, 2010 10:18 PM