{"id":112600,"date":"2026-08-10T07:00:00","date_gmt":"2026-08-10T14:00:00","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/oldnewthing\/?p=112600"},"modified":"2026-08-11T06:29:23","modified_gmt":"2026-08-11T13:29:23","slug":"20260810-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20260810-00\/?p=112600","title":{"rendered":"How can I perform a <CODE>Copy&shy;File<\/CODE> in unbuffered mode?"},"content":{"rendered":"<p>A customer was copying a file with <code>Copy\u00adFile<\/code>, but they wanted the file handles to be opened as <code>FILE_<wbr \/>FLAG_<wbr \/>NO_<wbr \/>BUFFERING<\/code>.<\/p>\n<p>We saw some time ago that <a title=\"How can I perform a CopyFile, but also flush the file buffers before the destination handle is closed?\" href=\"https:\/\/devblogs.microsoft.com\/oldnewthing\/20221007-00\/?p=107261\"> you can use the progress callback to <code>Copy\u00adFile\u00adEx<\/code> or <code>Copy\u00adFile2<\/code> to flush the output handle<\/a>. Maybe we can use the progress callback to open the handle as unbuffered?<\/p>\n<p>Nope, that doesn&#8217;t work because the progress callback gives you the already-opened handle. You can&#8217;t change its buffering flag after the fact.<\/p>\n<p>But that&#8217;s okay, because <code>Copy\u00adFile\u00adEx<\/code> and <code>Copy\u00adFile2<\/code> also have a flags parameter, and one of the flags is <code>COPY_<wbr \/>FILE_<wbr \/>NO_<wbr \/>BUFFERING<\/code>, which means that the handle should be opened as <code>FILE_<wbr \/>FLAG_<wbr \/>NO_<wbr \/>BUFFERING<\/code>.<\/p>\n<pre>BOOL success = CopyFileEx(\r\n    sourceFilePath, destinationFilePath,\r\n    nullptr, nullptr, nullptr,\r\n    COPY_FILE_NO_BUFFERING);\r\n<\/pre>\n<p>You can do the same with <code>Copy\u00adFile2<\/code>, but the flags are in the options structure.<\/p>\n<pre>COPYFILE2_EXTENDED_PARAMETERS parameters{};\r\nparameters.dwSize = sizeof(parameters);\r\nparameters.dwCopyFlags = COPY_FILE_NO_BUFFERING;\r\nHRESULT hr = CopyFile2(sourceFilePath, destinationFilePath, &amp;parameters);\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Try one of the fancier alternatives to <CODE>Copy&shy;File<\/CODE>.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-112600","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Try one of the fancier alternatives to <CODE>Copy&shy;File<\/CODE>.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112600","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=112600"}],"version-history":[{"count":1,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112600\/revisions"}],"predecessor-version":[{"id":112602,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/112600\/revisions\/112602"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=112600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=112600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=112600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}