CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jul 2009
    Posts
    33

    Clearing the archive bit

    Generally speaking I just want to clear the archive bit on a file.

    This will set the archive bit to "on" or 1 respectively:
    SetFileAttributes(L"README.txt",FILE_ATTRIBUTE_ARCHIVE);


    So how do I clear the archive bit, or make it 0?

    Any help is much appreciated!

    Regards,

    - Mac

  2. #2
    Join Date
    Jul 2009
    Posts
    33

    Re: Clearing the archive bit

    Ah nvm, a swift adjustment to #define and I'm good to go

  3. #3
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Clearing the archive bit

    Quote Originally Posted by Macgoober View Post
    This will set the archive bit to "on" or 1 respectively:
    SetFileAttributes(L"README.txt",FILE_ATTRIBUTE_ARCHIVE);
    Please note that this will also drop all other file attributes (will reset them to 0).

    Quote Originally Posted by Macgoober
    Ah nvm, a swift adjustment to #define and I'm good to go
    I am curious - what adjustment to what #define?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  4. #4
    Join Date
    Jul 2009
    Posts
    33

    Re: Clearing the archive bit

    Quote Originally Posted by VladimirF View Post
    Please note that this will also drop all other file attributes (will reset them to 0).


    I am curious - what adjustment to what #define?
    When the attribute is "on" its given value is 32. By using define you can force it to output 128 (off):

    #define FILE_ATTRIBUTE_ARCHIVE 0

  5. #5
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Clearing the archive bit

    Quote Originally Posted by Macgoober View Post
    When the attribute is "on" its given value is 32. By using define you can force it to output 128 (off):

    #define FILE_ATTRIBUTE_ARCHIVE 0
    Two things:
    1. NEVER ever redefine system constants. Also, you didn’t have to – could just call
    Code:
    SetFileAttributes(L"README.txt",0);
    2. As I’ve mentioned in post above, this will at the same time remove all other attributes that your file might have (system, hidden, etc.).
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  6. #6
    Join Date
    Jul 2009
    Posts
    33

    Re: Clearing the archive bit

    Quote Originally Posted by VladimirF View Post
    Two things:
    1. NEVER ever redefine system constants. Also, you didn’t have to – could just call
    Code:
    SetFileAttributes(L"README.txt",0);
    2. As I’ve mentioned in post above, this will at the same time remove all other attributes that your file might have (system, hidden, etc.).
    Just out of blatant curiosity, why should one never redefine system constants?
    The answer is obvious as to what could happen, but in this case I'm setting an insignificant variable.

    The only danger I know of would be altering a constant that would change the state of the OS.

    Let me know!

    Regards,

    - Mac

  7. #7
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Clearing the archive bit

    The fact that the "constant" is a macro definition means that your change will remain in effect for all remaining object files to be compiled. This includes any system header files you may include. This may cause some undesired behavior.

    Viggy

  8. #8
    Join Date
    Sep 2009
    Posts
    19

    Re: Clearing the archive bit

    The correct way to do this is by a read-modify-write operation, this way all other attributes will remain intact:

    SetFileAttributes (filename, GetFileAttributes(filename)&~FILE_ATTRIBUTE_ARCHIVE);

  9. #9
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Clearing the archive bit

    Quote Originally Posted by Macgoober View Post
    When the attribute is "on" its given value is 32. By using define you can force it to output 128 (off):

    #define FILE_ATTRIBUTE_ARCHIVE 0
    And how that ... thing could clear archive bit???
    Best regards,
    Igor

  10. #10
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Clearing the archive bit

    Quote Originally Posted by Igor Vartanov View Post
    And how that ... thing could clear archive bit???
    I assume he then calls:
    Code:
    SetFileAttributes(L"README.txt",FILE_ATTRIBUTE_ARCHIVE);
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured