Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 07:10, 12 December 2007.

Folder Operations

From Forum Nokia Wiki

Following code snippets are different fucntions which can be perfomed on Fodler/Directory.

Header File: LFolderAll.h

#include <f32file.h>
#include <bautils.h>
#include <aknnotewrappers.h>
 
#include <e32base.h>
 
_LIT(KFolderPath,"\\System\\Test\\");
 
_LIT(KDirectoryName,"\\System\\Test\\");
 
class CLFolderAll
{
	public:
 
		void CallCreate();
		void CallDelete();
		void CallDeleteFolderAndFiles();
		void CallDeleteFolderTree();
 
		void CallIsFolder();
 
                void CallDeleteSpecificFiles(TDesC& aWild);
 
		TBool MkDir(const TDesC &aPath); //RFs
		
		//The directory must be empty and cannot be the root directory.
		TBool RmDir(const TDesC &aPath); //RFs
 
		//The directory may not be empty and can remove all sub files too
		TBool RmDirAndFiles(const TDesC &aDirName); // CFileMan
 
                TBool RmSpecificFiles(TDesC& aWild); // CFileMan
};


Source File: LFolderAll.cpp

#include "LFolderAll.h"
 
void CLFolderAll::CallCreate()
{
	CAknInformationNote* iInfo = new (ELeave) CAknInformationNote;
	TBuf16<50> iFolderPath;
	iFolderPath.Copy(KFolderPath);
 
	TBool result=MkDir(iFolderPath);
	
	if(result)
		iInfo->ExecuteLD(_L("Folder Created"));
	else
		iInfo->ExecuteLD(_L("Folder Not Created"));
}
 
void CLFolderAll::CallDelete()
{
	CAknInformationNote* iInfo = new (ELeave) CAknInformationNote;
	TBuf16<50> iFolderPath;
	iFolderPath.Copy(KFolderPath);
 
	TBool result=RmDir(iFolderPath);
	
	if(result)
		iInfo->ExecuteLD(_L("Folder Deleted"));
	else
		iInfo->ExecuteLD(_L("Folder Not Deleted"));
}
 
void CLFolderAll::CallDeleteFolderAndFiles()
{
	CAknInformationNote* iInfo = new (ELeave) CAknInformationNote;
	TBuf16<50> iDirectoryPath;
	iDirectoryPath.Copy(KDirectoryName);
 
	TBool result=RmDirAndFiles(iDirectoryPath);
 
	if(result)
		iInfo->ExecuteLD(_L("Folder n Files Deleted"));
	else
		iInfo->ExecuteLD(_L("Folder n Files Not Deleted"));
}
 
void CLFolderAll::CallDeleteFolderTree()
{
	CAknInformationNote* iInfo = new (ELeave) CAknInformationNote;
	TBuf16<50> iDirectoryPath;
	iDirectoryPath.Copy(KDirectoryName);
 
	TBool result=RmDirAndFiles(iDirectoryPath);
 
	if(result)
		iInfo->ExecuteLD(_L("FolderTree Deleted"));
	else
		iInfo->ExecuteLD(_L("FolderTree Not Deleted"));
}
 
void CLFolderAll::CallDeleteSpecificFiles(TDesC& aWild)
{
	CAknInformationNote* iInfo = new (ELeave) CAknInformationNote;
 
	TBuf16<50> iFolderPath;
	iFolderPath.Copy(KDirectoryName);
        iFolderPath.Append(aWild);
 
	TBool result=RmSpecificFiles(iFolderPath);
	
	if(result)
		iInfo->ExecuteLD(_L("Files Deleted"));
	else
		iInfo->ExecuteLD(_L("Files Not Deleted"));
}
 
TBool CLFolderAll::MkDir(const TDesC &aPath)
{
	RFs iFs;
	iFs.Connect();
 
	TInt iErr=iFs.MkDir(aPath);
	iFs.Close();
	if(iErr==KErrNone)
		return ETrue;
	else
		return EFalse;
}
 
TBool CLFolderAll::RmDir(const TDesC &aPath)
{
	RFs iFs;
	iFs.Connect();
 
	TInt iErr=iFs.RmDir(aPath);
	iFs.Close();
	if(iErr==KErrNone)
		return ETrue;
	else
		return EFalse;
}
 
TBool CLFolderAll::RmDirAndFiles(const TDesC &aDirName)
{
	RFs iFs;
	iFs.Connect();
 
	CFileMan* iFileMan=CFileMan::NewL(iFs);
	CleanupStack::PushL(iFileMan);
 
	TInt iErr=iFileMan->RmDir(aDirName);
 
	CleanupStack::PopAndDestroy(iFileMan);
	iFs.Close();
 
	if(iErr==KErrNone)
		return ETrue;
	else
		return EFalse;
}
 
TBool CLFolderAll::RmSpecificFiles(TDesC& aWild)
{
        RFs iFs;
	iFs.Connect();
 
	CFileMan* iFileMan=CFileMan::NewL(iFs);
	CleanupStack::PushL(iFileMan);
 
	TInt iErr=iFileMan->Delete(aWild);
 
	CleanupStack::PopAndDestroy(iFileMan);
	iFs.Close();
 
	if(iErr==KErrNone)
		return ETrue;
	else
		return EFalse;
}

- Paste LFolderAll.h header file in your inc folder. - Paste LFolderAll.cppsource file in your src folder. - Include this LFolderAll.h your CYrAppUi.h file.

Like:
#include <LFolderAll.h>

- Declare an object in your CYrAppUi.h file.Like:

....
.....private: // Data
	CLFolderAll* iFolderAll;
....

- Finally call these fucntions from the HandleCommand() from CYrAppUi.Cpp file. Like:

void CYrAppUi::HandleCommandL( TInt aCommand )
    {
    switch( aCommand )
        {
        case EEikCmdExit:
        case EAknSoftkeyExit:
            Exit();
            break;
        case ELFolderOperaionsCreateFolder:
            {
		iFolderAll->CallCreate();
            }
            break;
        case ELFolderOperaionsDeleteFolder:
	{
		iFolderAll->CallDelete();
	}
	break;
        case ELFolderOperaionsDeleteFolderAndFiles:
	{
		iFolderAll->CallDeleteFolderAndFiles();
	}
	break;
        case ELFolderOperaionsDeleteFolderTree:
	{
		iFolderAll->CallDeleteFolderTree();
	}
	break;
        case ELFolderOperationsDeleteSpecificFiles:
        {
                iFolderAll->CallDeleteSpecificFiles(_L("*.xml"));
        }
        break;
 
        default:
            break;        
        }
    }

NOTE: You need to add efsrv.lib, bafl.lib in your .mmp file.

Related Discussions
Thread Thread Starter Forum Replies Last Post
wireless toolkit & nokia classes fatxy Mobile Java Tools & SDKs 2 2002-09-18 11:40
hi nandi1225 General Symbian C++ 12 2008-03-03 11:27
Can I retrieve "Received File" folder by JSR-75? psycohk Mobile Java General 6 2006-11-28 02:17
How to put my Symbian game app in the "Game" folder in 7650? cs_lcmaa General Symbian C++ 1 2002-12-04 13:31
Qusestion about application icon after installing? sparklezou General Symbian C++ 5 2007-04-30 08:59
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX