-
August 21st, 2009, 09:59 PM
#1
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
-
August 21st, 2009, 10:16 PM
#2
Re: Clearing the archive bit
Ah nvm, a swift adjustment to #define and I'm good to go
-
August 22nd, 2009, 12:19 PM
#3
Re: Clearing the archive bit
Originally Posted by Macgoober
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).
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...
-
August 22nd, 2009, 01:19 PM
#4
Re: Clearing the archive bit
Originally Posted by VladimirF
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
-
August 24th, 2009, 02:37 PM
#5
Re: Clearing the archive bit
Originally Posted by Macgoober
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...
-
August 24th, 2009, 07:24 PM
#6
Re: Clearing the archive bit
Originally Posted by VladimirF
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
-
August 25th, 2009, 11:54 AM
#7
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
-
September 2nd, 2009, 05:22 AM
#8
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);
-
September 2nd, 2009, 09:24 AM
#9
Re: Clearing the archive bit
Originally Posted by Macgoober
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
-
September 2nd, 2009, 11:59 PM
#10
Re: Clearing the archive bit
Originally Posted by Igor Vartanov
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|