Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Locking files in VB6

Locking files in VB6

Scheduled Pinned Locked Moved Visual Basic
questionhelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    steff kamush
    wrote on last edited by
    #1

    :rose::rose: How do lock a file in VB6 without hardcoding to append a .lock ext to the file name? How do i unlock? Pls help

    D 1 Reply Last reply
    0
    • S steff kamush

      :rose::rose: How do lock a file in VB6 without hardcoding to append a .lock ext to the file name? How do i unlock? Pls help

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      What do you mean by lock? It doesn't sound like the standard definition of the term. Besides, using .lock just changes the file extension, not any exclusive rights to the file. Are you trying to get exclusive access to the file? If so, then your Open statement should look something like:

      Open "filename.ext" For Binary Access Read Lock Read Write As #1

      Use whatever File Mode and Access you want, but the important part is the Lock modifier. RageInTheMachine9532

      S 1 Reply Last reply
      0
      • D Dave Kreskowiak

        What do you mean by lock? It doesn't sound like the standard definition of the term. Besides, using .lock just changes the file extension, not any exclusive rights to the file. Are you trying to get exclusive access to the file? If so, then your Open statement should look something like:

        Open "filename.ext" For Binary Access Read Lock Read Write As #1

        Use whatever File Mode and Access you want, but the important part is the Lock modifier. RageInTheMachine9532

        S Offline
        S Offline
        steff kamush
        wrote on last edited by
        #3

        hi RageInTheMachine9532, you r right i dint mean the std locking of files. i want many app instances to share a folder of .tif files. if app1 is using a file, it renames it with a .lock ext so app2 knows it is being modified by checking the ext. before an app exits, it renames files its been using from .lock to .tif. problem is if app1 crashes, the files remain with a .lock ext n neither app1 nor app2 can use them! how do i handle this? i mean without resorting to the normal windows locking.. :rose::rose:

        D 1 Reply Last reply
        0
        • S steff kamush

          hi RageInTheMachine9532, you r right i dint mean the std locking of files. i want many app instances to share a folder of .tif files. if app1 is using a file, it renames it with a .lock ext so app2 knows it is being modified by checking the ext. before an app exits, it renames files its been using from .lock to .tif. problem is if app1 crashes, the files remain with a .lock ext n neither app1 nor app2 can use them! how do i handle this? i mean without resorting to the normal windows locking.. :rose::rose:

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Well, the locking is the only "sure" way to control file access and you don't have to deal with renaming stuff back when you crash. The problem you have is this: When AppInstance1 checks for the availability of File1.tif, it's there. The next step, is for it to rename File1.tif to File1.locked. But, What if AppInstance2 found that File1.tif was available at (nearly) the same time, say, between AppInstance1 finding the file and renaming it? In this case, BOTH instances will find the file, but only one will succeed in renaming it. How is this case handled? It's too much of a pain to write your own file locking scheme when Windows has locking built in. It also has the advantage of being "thread safe", where your custom scheme does not. RageInTheMachine9532

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups