zoukankan      html  css  js  c++  java
  • 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,然后重新编译

    下面是练习用到的代码

    代码
    #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

  • 相关阅读:
    使用Navicat for Oracle新建表空间、用户及权限赋予---来自烂泥
    NonAction与ChildActionOnly
    C# Monitor的Wait和Pulse方法使用详解
    机械键盘简介
    【转载】 中小型研发团队架构实践
    BinaryReader 自己写序列化
    显式接口实现
    AssemblyVersion和AssemblyFileVersion的区别
    自定义设置程序集版本重定向和程序集位置的信息
    单例模式中的属性实现
  • 原文地址:https://www.cnblogs.com/zziss/p/1650233.html
Copyright © 2011-2022 走看看