⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getdir.cpp

📁 《基于symbian os 的手机开发与应用》 源代码 何伟 著
💻 CPP
字号:
// GetDir.cpp
//
// Copyright (c) 2005 Neusoft Institute of Information Technology.Chengdu  
// All rights reserved.

// written by hewei
//  
// version 1.0

//Date: 2005-10-31

// This program demostrate how to use HBufC. 

// NOTE: the structure of this example is different to standard E32 examples


#include <e32cons.h>
#include <f32file.h>

  // All messages written to this
LOCAL_D CConsoleBase* console;

// Function prototypes
 void callExampleL();
 void doExampleL();
void PrintDirInfo(const TEntry& );


//////////////////////////////////////////////////////////////////////////////
//
// Main function called by E32
//
//////////////////////////////////////////////////////////////////////////////
GLDEF_C TInt E32Main()
    {
	  // Get cleanup stack
	CTrapCleanup* cleanup=CTrapCleanup::New();

	 // Some more initialization, then do the example
    TRAPD(error,doExampleL());
	
	  
	  // callExampleL() should never leave.
	_LIT(KMsgPanicEpoc32ex,"EPOC32EX");
	__ASSERT_ALWAYS(!error,User::Panic(KMsgPanicEpoc32ex,error));

  // destroy the cleanup stack
	delete cleanup;
	
	  // return
	return 0;
    }


//////////////////////////////////////////////////////////////////////////////
//
//
//
//////////////////////////////////////////////////////////////////////////////
void doExampleL()
{
  	_LIT(KPressAnyKey,"[Press any key...OK]");
	//Get Console;
	_LIT(KMsgExampleCode,"Symbian OS Example Code");
	console = Console::NewL(KMsgExampleCode,TSize(KConsFullScreen,KConsFullScreen));
		// Put console onto the cleanup stack.
	CleanupStack::PushL(console);

	int error;
	TRAP(error,callExampleL());
	//TRAPD(error,callExampleL());
    if(error)
	{
		_LIT(KERROR,"error occured!\n");
		console->Printf(KERROR);
	
	}
	else{
      _LIT(KNOLEAVE,"No Leave!\n");
		console->Printf(KNOLEAVE);
	}
	console->Printf(KPressAnyKey);
	console->Getch();
		// Remove the console object from the cleanupstack
	  // and destroy it. 	
	CleanupStack::PopAndDestroy();
}

void callExampleL() 
    {
   RFs iFs;
   User::LeaveIfError(iFs.Connect());//connect to file server
  
   _LIT(KPath,"c:\\myfile\\");
   _LIT(KAllPath,"c:\\myfile\\txt\\");
   iFs.MkDir(KPath);// Create a directory
   iFs.MkDirAll(KAllPath); //Creat a directory tree
   
   //Get Session Path
   TBuf<20> sessionPath;
   User::LeaveIfError(iFs.SessionPath(sessionPath));
   _LIT(K1,"session path is:");
   _LIT(KRETURN,"\n");
   console->Printf(K1);
   console->Printf(sessionPath);
   console->Printf(KRETURN);
 
   //Get Default Path
  TBuf<20> DefaultPath;
  User::LeaveIfError(iFs.SessionPath(DefaultPath));
  _LIT(K2,"default path is:");
   console->Printf(K2);
   console->Printf(DefaultPath);
   console->Printf(KRETURN);
   
   //Set Session Path
   _LIT(KNewPath,"c:\\myfile\\");
   User::LeaveIfError(iFs.SetSessionPath(KNewPath));
   User::LeaveIfError(iFs.SessionPath(sessionPath));
   console->Printf(K2);
   console->Printf(sessionPath);
   console->Printf(KRETURN);

  //Get Dir Information
   _LIT(KDIR,"C:\\");
   CDir* dir=NULL;
   User::LeaveIfError(iFs.GetDir(KDIR,KEntryAttNormal|KEntryAttMatchMask,ESortNone,dir));
   for(TInt i=0;i<dir->Count();i++)
   {
	   PrintDirInfo((*dir)[i]);
	   console->Printf(KRETURN);
	   console->Getch();
   }

//Close file server
   iFs.Close();


}
void PrintDirInfo(const TEntry& aEntry)
{
	//Some Infomation
	_LIT(KRETURN,"\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(KRETURN);
	TBuf<30> dateString;
	_LIT(KDateString4,"%Y%M%D%/0%1%/1%2%/2%3%/3 %-B%:0%J%: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);
    else if(aEntry.IsReadOnly())
	    console->Printf(KIsReadOnly);
	else if(aEntry.IsHidden())
		console->Printf(KIsHidden);
	else if(aEntry.IsSystem())
		console->Printf(KIsSystem);
	else if(aEntry.IsArchive())
		console->Printf(KIsArchive);
}











⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -