CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Locking files

  1. #1
    Join Date
    Jul 2001
    Posts
    15

    Locking files

    Can anyone tell me about the locks that I can put in files accessed using OPEN method? What is the difference between LOCK READ,LOCK WRITE,LOCK READ WRITE and SHARED?



  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Locking files

    Lock read = other processes (other programs) cannot read the file
    Lock write = other cannot write to file (but can read it)
    Shared= other can read or write the file
    lock read Write = other cannot open the file for reading or for writing

    Here a couple of example from MSDN


    This code example opens the file in Binary mode for reading; other processes can't read file.
    Open "TESTFILE" For Binary Access Read Lock Read As #1

    This code example opens the file for sequential output; any process can read or write to file.
    Open "TESTFILE" For Output Shared As #1
    ' Close before reopening in another mode.
    Close #1




    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
    and all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

    The Rater
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured