1

When the file is being written to the disk, does the Windows System already consider the file exists or it waits until the writing process is done?

Basically, I have a script that checks if a directory has newly added files per minute. If there's one, I programming upload it to an API endpoint. But the problem now is that the file being uploaded is incomplete for some reason.

I'm trying to figure out if Windows consider the file exists even if it's not done writing. I assume it only shows there after it's done writing, but I'm not sure.

File System: NTFS

HelloThere
  • 113
  • 4

1 Answers1

1

When it starts writing the file, it has to create it, and as soon as it's created, it exists. This perforce is true for any file system. And it really can't be any other way, because the process creating the file may actually hold it open for possibly several hours, writing into it repeatedly, before finalizing and closing it, and you don't want to have another file created with the same name while that's happening; and another process also may want to deal with it by name during that time. In Windows, it is possible to open a file in exclusive mode, so that if anyone else has the file open your open will fail; in that case, you know it's still being written and you can hold off and try again in a few seconds.

tsc_chazz
  • 905
  • 3
  • 14