Re: Checking if file being accessed

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Tue, 10 Jun 2008 18:38:46 -0700, tshad <tshad@xxxxxxxxxxxxxx> wrote:

[...]
Most unhelpfully, you could find the file
available, but then it could become unavailable by the time you get
to try to open it.

In my case, this wouldn't happen.

Says you.

Unless you have somehow set the file permissions so that only your process has access to the file, you cannot assume in your code that the file will remain unavailable just because at some point in time it was.

I am watching the folder with a
filewatcher Service and the only access would be the person dropping the
file in my folder and my accessing it.

That may be the typical case, even by far. But you can't assume it.

If you want to include some sort of retry logic, so that you can
gracefully deal with situations where something else might also be
using the file, then do so. But once you've successfully opened the
file, just use the opened file. Anything less is just pointless
file-twiddling.

Probably right.

I am still curious as to why the FileShare.none wouldn't create an error, if
the file were still being written to.

It probably doesn't. The most likely reason that the file is inaccessible is because _your_ process has it open, due to the successful call to File.Open(). That's what I said before, and I still believe it. :)

Pete
.



Relevant Pages

  • Re: Start Menu - right click
    ... Put the check mark back in Enable dragging and dropping. ... MS-MVP Windows Media Center\Windows Powered Smart Display ... >> else such as the desktop or a folder. ...
    (microsoft.public.windowsxp.customize)
  • Re: Cant drag & drop files in XP on new computer
    ... sure "enable dragging and dropping" in ticked. ... Good luck. ... Woody ... > files from folder to folder. ...
    (microsoft.public.windowsxp.general)
  • Re: Disable Auto Expand On Drag & Drop In Windows Explorer
    ... When I move or copy a file, using Windows Explorer, I drag the ... (Unfortunately, this also puts a different folder, a sub-folder, under ... Open submenus when I pause on them with my mouse. ... This is enabled by default and can be hazardous when dragging and dropping. ...
    (microsoft.public.windowsxp.general)
  • Re: Copying files.
    ... folder to another, the computer will copy the file to the new folder and ... erase the file in the original folder. ... There are certain rules for dragging and dropping. ...
    (microsoft.public.windowsxp.accessibility)
  • Re: library listings
    ... You are dropping the folder to be listed on the ... script icon, right? ... >>> the entire file name is on one line with quotes around it. ...
    (microsoft.public.windowsxp.music)