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. C / C++ / MFC
  4. Does DeleteFile function returns immediatly?

Does DeleteFile function returns immediatly?

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 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.
  • D Offline
    D Offline
    Donguy1976
    wrote on last edited by
    #1

    Hello there, If i call DeleteFile on a file that's pretty large, does the function wait until the entire file is deleted before returning? Or does it return immediately? i.e., the control is passed to OS to complete the task of deletion and then return immediately? For e.g., if i am deleteing 5 files inside a loop and 2 of them happen to be larger size, will it wait until each file is completely deleted before going to the next one? If it doesn't, then there's a probability that when the next file is called by DeleteFile the previous one might still be in the process of deletion and it could fail. Is there a possibility like that?

    J J 2 Replies Last reply
    0
    • D Donguy1976

      Hello there, If i call DeleteFile on a file that's pretty large, does the function wait until the entire file is deleted before returning? Or does it return immediately? i.e., the control is passed to OS to complete the task of deletion and then return immediately? For e.g., if i am deleteing 5 files inside a loop and 2 of them happen to be larger size, will it wait until each file is completely deleted before going to the next one? If it doesn't, then there's a probability that when the next file is called by DeleteFile the previous one might still be in the process of deletion and it could fail. Is there a possibility like that?

      J Offline
      J Offline
      jeron1
      wrote on last edited by
      #2

      From the documentation I'm guessing that it will not return immediately, accurate return codes require the operation to complete. Yikes! Note to self...read the whole thing first! sorry.

      1 Reply Last reply
      0
      • D Donguy1976

        Hello there, If i call DeleteFile on a file that's pretty large, does the function wait until the entire file is deleted before returning? Or does it return immediately? i.e., the control is passed to OS to complete the task of deletion and then return immediately? For e.g., if i am deleteing 5 files inside a loop and 2 of them happen to be larger size, will it wait until each file is completely deleted before going to the next one? If it doesn't, then there's a probability that when the next file is called by DeleteFile the previous one might still be in the process of deletion and it could fail. Is there a possibility like that?

        J Offline
        J Offline
        Jochen Arndt
        wrote on last edited by
        #3

        As far as I know, the function returns immediately and the deletion occurs in the background. This is always true if the file is still opened (see DeleteFile[^] in the MSDN):

        Quote:

        The DeleteFile function marks a file for deletion on close. Therefore, the file deletion does not occur until the last handle to the file is closed.

        Overall, there should be no significant difference in time for large and small files because the file data itself are left unchanged on the disk. Only the directory entries are touched.

        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