Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change onlyread files

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi.

Please, Could you help me?

I need change a file fron onlyread status to normal status.

Thanks a lot.
 
I had to do this a while back... here is my code... just cut and paste into a MFC console app. This will traverse all subdirectories as well and remove the read only bit.

Matt

/////// CODE //////////////////////

Code:
// RmReadOnlyBit.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "RmReadOnlyBit.h"
#include <direct.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;
int RemoveReadOnlyBit();

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
	int nRetCode = 0;

	// initialize MFC and print and error on failure
	if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
	{
		// TODO: change error code to suit your needs
		cerr << _T(&quot;Fatal Error: MFC initialization failed&quot;) << endl;
		nRetCode = 1;
	}
	else
	{
		// TODO: code your application's behavior here.
		RemoveReadOnlyBit();
	}

	return nRetCode;
}

int RemoveReadOnlyBit()
{
	CFileFind finder;
	CString fileName;

	bool bImagesExist = (bool)finder.FindFile(&quot;*.*&quot;);


	while(bImagesExist)
	{
		bImagesExist = finder.FindNextFile();

		if(finder.IsDirectory())continue;

		fileName = finder.GetFileName();

		CFileStatus fs;
		CFile::GetStatus(fileName,fs);

		fs.m_mtime=0;
		fs.m_attribute &= ~(CFile::readOnly);

		CFile::SetStatus(fileName,fs);

		cout<<&quot;Removed read only bit on &quot;<<(LPCTSTR)fileName<<endl;
	}

	bool bWorking = finder.FindFile(&quot;*.*&quot;);
	while(bWorking)
	{
		bWorking = finder.FindNextFile();

		if(finder.GetFileName() != &quot;.&quot; && finder.GetFileName() != &quot;..&quot;)
		{
			if(finder.IsDirectory())
			{
				chdir((LPCTSTR)finder.GetFileName());
				RemoveReadOnlyBit();
			}
		}
	}
	chdir(&quot;..&quot;);
	return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top