RFs 目录操作

RFs 目录操作

RFs 可以通过 Connect() 连接到文件服务器,完毕后通过 Close() 关闭连接

常用操作:

  1. MkDir 与 MkDirAll 创建目录
  2. GetDir 可以得到 目录的列表到一个 CDir 对像中,这个CDir保存每个一目录的信息,用 TEntry 保存
  3. 通过 TEntry 得到每个目录的信息
  4. 注意的是对于目录的结尾一定加上 “\\”,否则认为不是一个目录
  5. SessionPath 会得到当前会话的路径,SetSessionPath 设置路径
  6. 头文件加上 f32file.h ,mmp 文件的 library 中添加上 efsrv.lib,然后重新编译

下面是练习用到的代码

ExpandedBlockStart.gif 代码
#include  < f32file.h >

//   Constants
_LIT(KTextConsoleTitle,  " Console " );
_LIT(KTextFailed, 
"  failed, leave code = %d " );
_LIT(KTextPressAnyKey, 
"  [press any key]\n " );

//   Global Variables
LOCAL_D CConsoleBase *  console;   //  write all messages to this
LOCAL_D RFs iFs;
void  printDriveInfo()
{
 
//  连接文件服务器
 User::LeaveIfError(iFs.Connect());
 _LIT(KEnter,
" \n " );
 _LIT(KPromp,
" There are drives list:\n " );
 _LIT(KChar,
" %c\n " );
 console
-> Printf(KPromp);
 TChar DriveLetter;
 TDriveList dList;
 iFs.DriveList(dList);
 
for (TInt i = 0 ;i < dList.Length();i ++ )
 {
  
if  (dList[i])
  {
   iFs.DriveToChar(i,DriveLetter);
   console
-> Printf(KChar,DriveLetter);
   console
-> Printf(KEnter);
  }
 }

 
//  用完后,关闭连接
 iFs.Close();
}
void  printDirInfo( const  TEntry & );
void  viewDirInfo()
{
 User::LeaveIfError(iFs.Connect());
 _LIT(KMyDir,
" c:\\myfile\\ " );
 _LIT(KmyDirAll,
" c:\\mytxtfile\\txt\\ " );
    _LIT(KretInfo,
" return code=%d " );
 TInt iRet;
 iRet 
=  iFs.MkDir(KMyDir);
 console
-> Printf(KretInfo,iRet);
 iRet 
=  iFs.MkDirAll(KmyDirAll);
 console
-> Printf(KretInfo,iRet);
 TBuf
< 20 >  sessionPath;
 User::LeaveIfError(iFs.SessionPath(sessionPath));
 _LIT(K1,
" session path is: " );
 _LIT(KEnter,
" \n " );
 console
-> Printf(K1);
 console
-> Printf(sessionPath);
 console
-> Printf(KEnter);
 TBuf
< 20 >  defaultSessionPath;
 User::LeaveIfError(iFs.DefaultPath(defaultSessionPath));
 _LIT(K2,
" default path: " );
 console
-> Printf(K2);
 console
-> Printf(defaultSessionPath);
 console
-> Printf(KEnter);
 _LIT(KNewPath,
" c:\\myfile\\ " );
 User::LeaveIfError(iFs.SetSessionPath(KNewPath));
 User::LeaveIfError(iFs.SessionPath(sessionPath));
 console
-> Printf(K1);
 console
-> Printf(sessionPath);
 console
-> Printf(KEnter);
 
    _LIT(KDir,
" C:\\mytxtfile\\ " );
 CDir
*  dir  =  NULL;
 console
-> ClearScreen();
 User::LeaveIfError(iFs.GetDir(KDir,KEntryAttNormal
| KEntryAttMatchMask,ESortNone,dir));
 
for (TInt i = 0 ;i < dir -> Count();i ++ )
 {
  printDirInfo((
* dir)[i]);
  console
-> Getch();
  console
-> ClearScreen();
  console
-> Printf(KEnter);
 }
 
 iFs.Close();
}
void  printDirInfo( const  TEntry &  aEntry)
{
 _LIT(Kentery,
" \n " );
 _LIT(KIsDir,
" directory\n " );
 _LIT(KIsReadOnly,
" Readonly\n " );
 _LIT(KIsHidden,
" Hidden\n " );
 _LIT(KIsSystem,
" System\n " );
 _LIT(KIsArchive,
" Archive\n " );
 console
-> Printf(aEntry.iName);
 console
-> Printf(Kentery);
 TBuf
< 30 >  dateString;
 _LIT(KDatestring4,
" %Y%M%D%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S\n " );
 aEntry.iModified.FormatL(dateString,KDatestring4);
 console
-> Printf(dateString);
 _LIT(KFmt1,
" size:%d bytes\n " );
 console
-> Printf(KFmt1,aEntry.iSize);
 
if  (aEntry.IsDir())
  console
-> Printf(KIsDir);
 
if  (aEntry.IsReadOnly())
  console
-> Printf(KIsReadOnly);
 
if  (aEntry.IsHidden())
  console
-> Printf(KIsHidden);
 
if  (aEntry.IsSystem())
  console
-> Printf(KIsSystem);
 
if  (aEntry.IsArchive())
  console
-> Printf(KIsArchive);
}
//   Local Functions
LOCAL_C  void  MainL( const  TDesC &  aArgs)
    {
    
//
    
//  add your program code here, example code below
    
//
    
// console->Write(_L("Hello, world!\n"));
 
// printDriveInfo();
 viewDirInfo();
    console
-> Printf(_L( " Command line args: \ " % S\ " \n " ),  & aArgs);
    }

 



安平2009@原创
qi_jianzhou@126.com

转载于:https://www.cnblogs.com/zziss/archive/2010/01/17/1650233.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值