C#: Wait till a file is free for renaming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Chanjal
    New Member
    • Jun 2008
    • 4

    #1

    C#: Wait till a file is free for renaming

    Hi,

    I need to rename a file. But it is been opened by another program, so i cannot rename it. Does anybody know how to wait till that file is inaccessed or free from that program?

    Thanks in advance,
    Chang.
    Last edited by Chanjal; Jun 1 '08, 12:18 PM. Reason: Wrong title.
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Originally posted by Chanjal
    Hi,

    I need to rename a file. But it is been opened by another program, so i cannot rename it. Does anybody know how to wait till that file is inaccessed or free from that program?

    Thanks in advance,
    Chang.
    Gee you could be waiting a long time, have you tried using threads?

    Comment

    • Chanjal
      New Member
      • Jun 2008
      • 4

      #3
      Originally posted by kenobewan
      Gee you could be waiting a long time, have you tried using threads?
      I didnt get a logic to what to wait for if even using a thread. I tried FileSystemWatch er but it didnt help though. It just throws event if any change happens but not look whether it is been used by any other process.

      Comment

      • kenobewan
        Recognized Expert Specialist
        • Dec 2006
        • 4871

        #4
        Originally posted by Chanjal
        I didnt get a logic to what to wait for if even using a thread. I tried FileSystemWatch er but it didnt help though. It just throws event if any change happens but not look whether it is been used by any other process.
        I was thinking your code tries to execute a rename, then you treat this process as a thread. Try searching the site as the topic of locked files has come up before.

        Comment

        Working...