WinApi SetFileAttributes slow-motion call












-1















Today I did some testing with the SetFileAttributes method and encountered a phenomenon I am not able to explain logically:



I wrote a short C program:



    #include <stdio.h>
#include <windows.h>

int main()
{
char* strFile = L"C:\test.txt";

if (SetFileAttributes(strFile, FILE_ATTRIBUTE_HIDDEN))
{
printf("File attribute changed.n");
}

printf("%d", GetLastError());

}


It is a test program that hides a folder or icon, and I want to do it fast, but unfortunately the process takes 1-2s.
If I hide the icon manually via properties and the checkbox selection 'Hidden', the icon is hidden promptly.



So, what makes the winapi call take so many time? Is there a way to optimize the call?



Thanks.










share|improve this question























  • Try closing Explorer or have it look at another directory. It might be that the file or directory is considered in use.

    – Paul Ogilvie
    Nov 28 '18 at 13:33






  • 1





    is exactly single call to SetFileAttributes take this time ? how you measure this ?

    – RbMm
    Nov 28 '18 at 14:17






  • 3





    no. i ask how many time take call SetFileAttributes. look like you even not measure this

    – RbMm
    Nov 28 '18 at 14:26






  • 2





    Explorer probably only checks for or otherwise gets notified of changes to file metadata that need to be reflected in its display every few seconds.

    – Shawn
    Nov 28 '18 at 14:37






  • 4





    I think it takes 2 seconds until the Explorer view is updated, not until the attribute was set. Try a GetFileAttributes after the Set.

    – Paul Ogilvie
    Nov 28 '18 at 14:37
















-1















Today I did some testing with the SetFileAttributes method and encountered a phenomenon I am not able to explain logically:



I wrote a short C program:



    #include <stdio.h>
#include <windows.h>

int main()
{
char* strFile = L"C:\test.txt";

if (SetFileAttributes(strFile, FILE_ATTRIBUTE_HIDDEN))
{
printf("File attribute changed.n");
}

printf("%d", GetLastError());

}


It is a test program that hides a folder or icon, and I want to do it fast, but unfortunately the process takes 1-2s.
If I hide the icon manually via properties and the checkbox selection 'Hidden', the icon is hidden promptly.



So, what makes the winapi call take so many time? Is there a way to optimize the call?



Thanks.










share|improve this question























  • Try closing Explorer or have it look at another directory. It might be that the file or directory is considered in use.

    – Paul Ogilvie
    Nov 28 '18 at 13:33






  • 1





    is exactly single call to SetFileAttributes take this time ? how you measure this ?

    – RbMm
    Nov 28 '18 at 14:17






  • 3





    no. i ask how many time take call SetFileAttributes. look like you even not measure this

    – RbMm
    Nov 28 '18 at 14:26






  • 2





    Explorer probably only checks for or otherwise gets notified of changes to file metadata that need to be reflected in its display every few seconds.

    – Shawn
    Nov 28 '18 at 14:37






  • 4





    I think it takes 2 seconds until the Explorer view is updated, not until the attribute was set. Try a GetFileAttributes after the Set.

    – Paul Ogilvie
    Nov 28 '18 at 14:37














-1












-1








-1








Today I did some testing with the SetFileAttributes method and encountered a phenomenon I am not able to explain logically:



I wrote a short C program:



    #include <stdio.h>
#include <windows.h>

int main()
{
char* strFile = L"C:\test.txt";

if (SetFileAttributes(strFile, FILE_ATTRIBUTE_HIDDEN))
{
printf("File attribute changed.n");
}

printf("%d", GetLastError());

}


It is a test program that hides a folder or icon, and I want to do it fast, but unfortunately the process takes 1-2s.
If I hide the icon manually via properties and the checkbox selection 'Hidden', the icon is hidden promptly.



So, what makes the winapi call take so many time? Is there a way to optimize the call?



Thanks.










share|improve this question














Today I did some testing with the SetFileAttributes method and encountered a phenomenon I am not able to explain logically:



I wrote a short C program:



    #include <stdio.h>
#include <windows.h>

int main()
{
char* strFile = L"C:\test.txt";

if (SetFileAttributes(strFile, FILE_ATTRIBUTE_HIDDEN))
{
printf("File attribute changed.n");
}

printf("%d", GetLastError());

}


It is a test program that hides a folder or icon, and I want to do it fast, but unfortunately the process takes 1-2s.
If I hide the icon manually via properties and the checkbox selection 'Hidden', the icon is hidden promptly.



So, what makes the winapi call take so many time? Is there a way to optimize the call?



Thanks.







c windows winapi icons






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 28 '18 at 13:25









d.rkd.rk

13




13













  • Try closing Explorer or have it look at another directory. It might be that the file or directory is considered in use.

    – Paul Ogilvie
    Nov 28 '18 at 13:33






  • 1





    is exactly single call to SetFileAttributes take this time ? how you measure this ?

    – RbMm
    Nov 28 '18 at 14:17






  • 3





    no. i ask how many time take call SetFileAttributes. look like you even not measure this

    – RbMm
    Nov 28 '18 at 14:26






  • 2





    Explorer probably only checks for or otherwise gets notified of changes to file metadata that need to be reflected in its display every few seconds.

    – Shawn
    Nov 28 '18 at 14:37






  • 4





    I think it takes 2 seconds until the Explorer view is updated, not until the attribute was set. Try a GetFileAttributes after the Set.

    – Paul Ogilvie
    Nov 28 '18 at 14:37



















  • Try closing Explorer or have it look at another directory. It might be that the file or directory is considered in use.

    – Paul Ogilvie
    Nov 28 '18 at 13:33






  • 1





    is exactly single call to SetFileAttributes take this time ? how you measure this ?

    – RbMm
    Nov 28 '18 at 14:17






  • 3





    no. i ask how many time take call SetFileAttributes. look like you even not measure this

    – RbMm
    Nov 28 '18 at 14:26






  • 2





    Explorer probably only checks for or otherwise gets notified of changes to file metadata that need to be reflected in its display every few seconds.

    – Shawn
    Nov 28 '18 at 14:37






  • 4





    I think it takes 2 seconds until the Explorer view is updated, not until the attribute was set. Try a GetFileAttributes after the Set.

    – Paul Ogilvie
    Nov 28 '18 at 14:37

















Try closing Explorer or have it look at another directory. It might be that the file or directory is considered in use.

– Paul Ogilvie
Nov 28 '18 at 13:33





Try closing Explorer or have it look at another directory. It might be that the file or directory is considered in use.

– Paul Ogilvie
Nov 28 '18 at 13:33




1




1





is exactly single call to SetFileAttributes take this time ? how you measure this ?

– RbMm
Nov 28 '18 at 14:17





is exactly single call to SetFileAttributes take this time ? how you measure this ?

– RbMm
Nov 28 '18 at 14:17




3




3





no. i ask how many time take call SetFileAttributes. look like you even not measure this

– RbMm
Nov 28 '18 at 14:26





no. i ask how many time take call SetFileAttributes. look like you even not measure this

– RbMm
Nov 28 '18 at 14:26




2




2





Explorer probably only checks for or otherwise gets notified of changes to file metadata that need to be reflected in its display every few seconds.

– Shawn
Nov 28 '18 at 14:37





Explorer probably only checks for or otherwise gets notified of changes to file metadata that need to be reflected in its display every few seconds.

– Shawn
Nov 28 '18 at 14:37




4




4





I think it takes 2 seconds until the Explorer view is updated, not until the attribute was set. Try a GetFileAttributes after the Set.

– Paul Ogilvie
Nov 28 '18 at 14:37





I think it takes 2 seconds until the Explorer view is updated, not until the attribute was set. Try a GetFileAttributes after the Set.

– Paul Ogilvie
Nov 28 '18 at 14:37












1 Answer
1






active

oldest

votes


















0














First of all: Thanks for your suggestions. You were right, the explorer view / the desktop gets only updated after the time I did mention.



I was able to solve the slowmotion issue by using the winapi call SHChangeNotify. It is important to combine the uFlags part with SHCNF_FLUSH, then the change is visible instantly.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53520513%2fwinapi-setfileattributes-slow-motion-call%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    First of all: Thanks for your suggestions. You were right, the explorer view / the desktop gets only updated after the time I did mention.



    I was able to solve the slowmotion issue by using the winapi call SHChangeNotify. It is important to combine the uFlags part with SHCNF_FLUSH, then the change is visible instantly.






    share|improve this answer




























      0














      First of all: Thanks for your suggestions. You were right, the explorer view / the desktop gets only updated after the time I did mention.



      I was able to solve the slowmotion issue by using the winapi call SHChangeNotify. It is important to combine the uFlags part with SHCNF_FLUSH, then the change is visible instantly.






      share|improve this answer


























        0












        0








        0







        First of all: Thanks for your suggestions. You were right, the explorer view / the desktop gets only updated after the time I did mention.



        I was able to solve the slowmotion issue by using the winapi call SHChangeNotify. It is important to combine the uFlags part with SHCNF_FLUSH, then the change is visible instantly.






        share|improve this answer













        First of all: Thanks for your suggestions. You were right, the explorer view / the desktop gets only updated after the time I did mention.



        I was able to solve the slowmotion issue by using the winapi call SHChangeNotify. It is important to combine the uFlags part with SHCNF_FLUSH, then the change is visible instantly.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 29 '18 at 7:30









        d.rkd.rk

        13




        13
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53520513%2fwinapi-setfileattributes-slow-motion-call%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)