How to distinguish a file from a folder.

Login to reply to this topic.
Wed, 2007-02-14 10:40
Joined: 2007-02-01
Forum posts: 28
Hi,

I have a function which needs to examine all files within a folder.  I'm currently doing this as follows:

void CProcessFile::ScanDirL(RFs& aFs, const TDesC& aDir, const TDesC& aWild)
   TFindFile find(aFs);
   CDir* dir;

   TParse parse;
   parse.Set(aWild, &aDir, NULL);
   TPtrC spec(parse.FullName());

   HBufC16 *tmpBuf = HBufC16::NewLC(KMaxPath);
   TPtr16 tmpPtr = tmpBuf->Des();
 
   if (!find.FindWildByPath(parse.FullName(), NULL, dir))
      {
      CleanupStack::PushL(dir);

      for(TInt i = 0; i < dir->Count(); i++)
         {
         parse.Set((*dir)[i].iName, &spec, NULL);
         tmpPtr = parse.FullName();         
         
         ProcessFile((const TDesC16&)*tmpBuf);

         }
      CleanupStack::PopAndDestroy(dir);
      }
   CleanupStack::PopAndDestroy(tmpBuf);
   return;

The problem with this code is that "parse.Set((*dir)[i].iName, &spec, NULL)"  returns both files and folders - I only want to know about files.   

Please can someone tell me how to either distinguish between a file and a directory, or provide an alternative filtering out directories. (For example, I note that CDirScan::SetScanDataL provides a filter, but this returns a list of all files in the hierarchy, not just the current folder.)

If it helps, this is being developed on Symbian 8, although it will be useful if the algorithm is also supported on earlier releases.


Many thanks,
Dave-V

Wed, 2007-02-14 12:42
Joined: 2003-12-05
Forum posts: 683
Re: How to distinguish a file from a folder.
You can use RFs::GetDir to get either files, directories or both.
Wed, 2007-02-14 12:56
Joined: 2005-02-11
Forum posts: 214
Re: How to distinguish a file from a folder.
Code:
CDirScan* scan = CDirScan::NewLC(fs);
scan->SetScanDataL(KFileFolder,KEntryAttMatchMask,ESortByName|EAscending,CDirScan::EScanDownTree);
CDir* folders = NULL;
TRAPD(error, scan->NextL(folders));
for(...)
{TEntry entry=(*folders)[i];
if(entry.IsDir())
continue;
}

"I only know that I know nothing." (Socrates)

Wed, 2007-02-14 13:23
Joined: 2007-02-01
Forum posts: 28
Re: How to distinguish a file from a folder.
Thanks  -  that's exactly what I needed.


Dave
  • Login to reply to this topic.