ID: Q117832
7.00 | 1.00 1.50 MS-DOS | WINDOWS kbprg kbprb
The information in this article applies to:
- Microsoft C/C++ version 7.0
- Microsoft Visual C++ for Windows, versions 1.0 and 1.5
Attempting to clear the archive bit of a file when the archive bit is already cleared causes the archive bit to be set.
This is expected behavior that results when the m_mtime member of the CFileStatus structure is not set to 0, indicating that the time should be updated. Because updating the time has the side effect of setting the archive bit for a file, this action takes precedence over clearing the archive bit when the bit was clear to begin with.
1. If you want to clear only the archive bit, set the m_mtime member
to 0, which indicates that you do not want to change the file time:
CFile::GetStatus("TEMP.DAT",fs);
fs.m_mtime=0;
fs.m_attribute = fs.m_attribute & !CFile::archive;
CFile::SetStatus("TEMP.DAT",fs);
2. Check to see whether the archive bit is clear instead of making a
redundant call to clear it:
CFile::GetStatus("TEMP.DAT",fs);
if(fs.m_attribute & CFile::archive)
{
fs.m_attribute = fs.m_attribute & !CFile::archive;
CFile::SetStatus("TEMP.DAT",fs);
}
To duplicate this behavior, create a test file called TEMP.DAT and run the sample code below:
// Using the MS-DOS ATTRIB command, watch the archive bit toggle
// after each time you run the program.
#define _DOS
#include <afx.h>
CFileStatus fs;
void main(void) {
CFile::GetStatus("TEMP.DAT",fs);
fs.m_attribute = fs.m_attribute & !CFile::archive;
CFile::SetStatus("TEMP.DAT",fs);
}
This behavior does not occur with Visual C++ 32-bit Edition.
The possible side effects of m_mtime on file attributes are discussed in the "Class Library Reference" for Visual C++, version 1.5, page 411.
Additional reference words: 7.00 1.00 1.50 2.00 2.50 KBCategory: kbprg kbprb KBSubcategory: MfcFileIO Keywords : kb16bitonly
Last Reviewed: July 23, 1997