This page was last modified 08:20, 9 April 2008.
How to calculate directory content
From Forum Nokia Wiki
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();
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| UPnP Software of N93 | perkusic | Wired and Wireless interfaces | 0 | 2006-12-29 19:22 |
| Copy file. | manugarrote | Python | 7 | 2008-07-11 03:27 |
| how to judge a Directory exist or not | zhang_guoqing | General Symbian C++ | 3 | 2003-06-11 15:08 |
| [announce] RaccoonOnMap: Raccoon + Google Maps | talakosk | Mobile Web Server | 18 | 2007-05-21 14:14 |
| Problem with AttachmentManagerL | jaahaavi | Symbian Networking & Messaging | 22 | 2007-02-12 21:03 |
