Writing Dir command in Symbian
For writing dir command we need to understand some classes
1. CDir
2. TEntry
CDir
It’s used for to get the directory & file names present in the file system.
TEntry
This is used to process a particular file or directory.
--->CDir contains collection of TEntry object, Each object represents a file or folder. How do we read the file system?. Yes First we need to read the file system then only we can proceed for that RFs class provides a method called GetDir() by using this we can read the file system.
CDir *listOfFiles = NULL;
fs.GetDir(_L("C:\\"), KEntryAttMaskSupported, ESortByName, listOfFiles);
KEntryAttMaskSupported = (readonly, hidden, system, volume, directory & Archive)
Bit Position
0th Read only flag
1st hidden bit
2nd system bit
3rd volume bit
4th directory bit
5th Archive bit
--->KEntryAttMaskSupported instead of this we can manually select the bit pattern for filtering the dir command stuff.
Our requirements are to get the hidden file, system file, directory & normal files. For that we will use the value 2 (hidden) + 4 (system) + 16(directory) = 22
fs.GetDir(_L("C:\\"), 22, ESortByName, listOfFiles);
This above statement will get the normal file, hidden file, system files and directory in listOfFiles object.
If you want to get only directories present in the path we need to pass “16” instead of 22. It’s all in the game of enabling bit.
Simple program segment for this dir command
RFs &fs = CCoeEnv::Static()->FsSession();
TBuf<500> buf;
CDir* listOfFiles = NULL;
fs.GetDir(_L("C:\\stalin\\"), 22, ESortByName, listOfFiles);
for(TInt i = 0; i <>Count(); i++)
{
const TEntry& fileEntry = (*listOfFiles)[i];
TBuf<256> name = fileEntry.iName;
buf.Append(name);
if (fileEntry.IsHidden())
buf.Append(_L("hidden"));
else if(fileEntry.IsDir())
buf.Append(_L("dir"));
else
buf.Append(_L("nor"));
buf.Append(_L("\n"));
}
delete listOfFiles;
CAknInformationNote *note = new (ELeave) CAknInformationNote;
note->ExecuteLD(buf);
If you are testing in the, go to
C:\Symbian\9.3\S60_3rd_FP2_Beta\epoc32\winscw\c
Create a folder “stalin” there create a normal file, hidden file and a folder then test by changing the value 22 in GetDir function call. You will understand how it works. :-)
4 comments:
Dude, You are an absolute loser!!!
Post a Comment