How to know a file is busy(read/write)?

  • Deall all;
        I want to know a file is busy before i use it. For example, when you clean Tash, and some file is using, sysytem will tell you can't remove it. I used NSFileBusy(in NSFileManager), but it didn't succseful. Waiting for you help. Thanks a lot.
  • What are you trying to do with the file?

    Even if there were a perfect API to provide detailed status of a file,
    that status can change between the time you check and act on the file.

    In most situations I encounter the real solution is to act on the file
    and then handle the error case at that time.

    Deric Horn
    Application Technologies Evangelist
    Apple Worldwide Developer Relations
    <deric...>

    On Jan 10, 2008, at 6:24 PM, shengjun_guan (ºÞÁn«T) wrote:

    > Deall all;
    > I want to know a file is busy before i use it. For example, when
    > you clean Tash, and some file is using, sysytem will tell you can't
    > remove it. I used NSFileBusy(in NSFileManager), but it didn't
    > succseful. Waiting for you help. Thanks a lot.
  • hi,

    Because i have one application to monitor one folder that files are created in.
    eg. file1 and file2 have been created in the folder. My application will send the file1 and file2
    to other application to open them.
    In some case, file1 have been finishing created.And file2 is creating . So, if i send the tow files for
    opening to other application. file2 will open fail.

    So, i want to check the file2 if is busy before i send.

    thanks a lot .

    ann

    -----Original Message-----
    From: Horn Deric [mailto:<deric...>]
    Sent: 2008/1/11 [¬P´Á¤­] ¤W¤È 11:08
    To: shengjun_guan (ºÞÁn«T)
    Cc: <cocoa-dev...>
    Subject: Re: How to know a file is busy(read/write)?

    What are you trying to do with the file?

    Even if there were a perfect API to provide detailed status of a file,
    that status can change between the time you check and act on the file.

    In most situations I encounter the real solution is to act on the file
    and then handle the error case at that time.

    Deric Horn
    Application Technologies Evangelist
    Apple Worldwide Developer Relations
    <deric...>

    On Jan 10, 2008, at 6:24 PM, shengjun_guan (ºÞÁn«T) wrote:

    > Deall all;
    > I want to know a file is busy before i use it. For example, when
    > you clean Tash, and some file is using, sysytem will tell you can't
    > remove it. I used NSFileBusy(in NSFileManager), but it didn't
    > succseful. Waiting for you help. Thanks a lot.
  • On 11 Jan 2008, at 05:19, shengjun_guan (ºÞÁn«T) wrote:

    > Because i have one application to monitor one folder that files are
    > created in.
    > eg. file1 and file2 have been created in the folder. My application
    > will send the file1 and file2
    > to other application to open them.
    > In some case, file1 have been finishing created.And file2 is
    > creating . So, if i send the tow files for
    > opening to other application. file2 will open fail.
    >
    > So, i want to check the file2 if is busy before i send.

    There is no such thing as a "busy" file on a UNIX system.  You need to
    redesign your application to work in a different way.  For instance,
    maybe files that your application acts on could have a different
    extension to the ones that are being created; renaming a file is an
    atomic operation, so once you've finished writing a file, you could
    then rename it to bring it to the attention of your other process.

    If the source code is available for all the programs in question, you
    may also be able to use advisory locks, or lock files, or even some
    other mechanism (for instance, you could use a socket to send the
    names of the files to process to the far end).

    Kind regards,

    Alastair.

    --
    http://alastairs-place.net
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today