Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to calculate directory content

From Wiki
Jump to: navigation, search
Article Metadata
Article
Created: Den123 (26 Jun 2007)
Last edited: hamishwillee (30 May 2013)

Class Header:

class TDirContentReader
{
public:
TDirContentReader( RFs& aFs, const TDesC& aDirName ):
iFs( aFs ), iDirName( aDirName ) {}
TInt Exec();
 
inline TUint DirsCount() { return iDirsCount; }
inline TUint FilesCount() { return iFilesCount; }
inline TInt64 FilesSize() { return iFileSize; }
 
private:
 
void ReadDirL( const TDesC& aDirName,
TUint& aDirsCount,
TUint& aFilesCount,
TInt64& aFileSize );
 
const TDesC& iDirName;
RFs& iFs;
TUint iDirsCount;
TUint iFilesCount;
TInt64 iFileSize;
};

Class Body:

TInt TDirContentReader :: Exec()
{
iDirsCount = 0;
iFilesCount = 0;
iFileSize = 0;
TInt execResult = KErrNone;
TRAP( execResult, ReadDirL( iDirName, iDirsCount, iFilesCount, iFileSize ) );
return execResult;
}
 
void TDirContentReader :: ReadDirL( const TDesC& aDirName,
TUint& aDirsCount,
TUint& aFilesCount,
TInt64& aFileSize )
{
CDir* fileList = NULL;
CDir* dirList = NULL;
 
User :: LeaveIfError(
iFs.GetDir( aDirName,
KEntryAttNormal | KEntryAttHidden | KEntryAttSystem,
ESortByName | EDirsFirst | EAscending,
fileList,
dirList ) );
 
 
aDirsCount += dirList->Count();
aFilesCount += fileList->Count();
for( TUint i = 0; i < fileList->Count(); i++ )
aFileSize += fileList->operator[](i).iSize;
delete fileList;
 
CleanupStack :: PushL( dirList );
for( TUint i = 0; i < dirList->Count(); i++ )
{
HBufC* buf = HBufC :: NewL( aDirName.Length() +
dirList->operator[](i).iName.Length() + 1);
 
TPtr ptr = buf->Des();
ptr.Append( aDirName );
ptr.Append( dirList->operator[]( i ).iName );
ptr.Append( KPathDelimiter );
 
CleanupStack :: PushL( buf );
ReadDirL( *buf, iDirsCount, iFilesCount, iFileSize );
CleanupStack :: PopAndDestroy( buf );
}
CleanupStack :: PopAndDestroy( dirList );
}

Usage example:

   RFs myFs;
User::LeaveIfError( myFs.Connect() );
_LIT( KResources, "Z:\\resource\\" );
TDirContentReader dirContentReader( &myFs, KResources() );
if (dirContentReader.Exec() == KErrNone )
{
// TInt64 totalSize = dirContentReader.FilesSize();
}
myFs.Close();
This page was last modified on 30 May 2013, at 04:38.
30 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×