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

📄 getanddelete.cpp

📁 自己写的一个删除文件的源代码
💻 CPP
字号:
/*
============================================================================
 Name        : GetAndDelete.cpp
 Author      : 
 Version     :
 Copyright   : Your copyright notice
 Description : GetAndDelete.cpp - source file
============================================================================
*/

#include "GetAndDelete.h"

#include <avkon.hrh>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <DeleteFiles.rsg>
#include <f32file.h>
#include <s32file.h>

// ================= MEMBER FUNCTIONS =======================

CGetAndDelete* CGetAndDelete::NewL( const TRect& aRect )
{
    CGetAndDelete* self = CGetAndDelete::NewLC( aRect );
    CleanupStack::Pop( self );
    return self;
}

CGetAndDelete* CGetAndDelete::NewLC( const TRect& aRect )
{
    CGetAndDelete* self = new ( ELeave ) CGetAndDelete;
	CleanupStack::PushL( self );
    self->ConstructL();
    return self;
}

void CGetAndDelete::ConstructL()
{
	GetDir();
}

CGetAndDelete::CGetAndDelete()
{
}

CGetAndDelete::~CGetAndDelete()
{
	if ( iDir )
	{
		delete iDir;
		iDir = NULL;
	}
}

void CGetAndDelete::GetDir()
{
	RFs iFs;
	iFs.Connect();
	_LIT(KDir,"c:\\Data\\");
	iFs.MkDir(KDir);
	User::LeaveIfError(iFs.GetDir(KDir,KEntryAttNormal|KEntryAttMatchMask,ESortNone,iDir));
	iFs.Close();
}

void CGetAndDelete::DeleteFile(const TDesC& aText)
{
	_LIT(KPath,"c:\\Data\\");
	RFs fs;
	RFile file;
	User::LeaveIfError(fs.Connect());
	TBuf<64> aAllName;
	TBuf<32> aFullName;
	TBuf<16> aFileName;
	TInt Num = iDir->Count();
	for (TInt i=0; i<Num; i++)
	{
		aFullName.Append((*iDir)[i].iName);
		TInt idx = aFullName.FindC(_L("."));
		if(idx>0){
			aFileName.Copy(aFullName.Mid(0, idx));
			if ( aFileName.Compare(aText)==0)
			{
				aAllName.Append(KPath);
				aAllName.Append(aFullName);
				fs.Delete(aAllName);
			}
			aFileName.Zero();
			aAllName.Zero();
		}
		aFullName.Zero();
	}
}

void CGetAndDelete::DeleteExtendFile(const TDesC& aText)
{
	_LIT(KPath,"c:\\Data\\");
	RFs fs;
	RFile file;
	User::LeaveIfError(fs.Connect());
	TBuf<64> aAllName;
	TBuf<32> aFullName;
	TBuf<16> aExtendName;
	TInt Num = iDir->Count();
	for (TInt i=0; i<Num; i++)
	{
		aFullName.Append((*iDir)[i].iName);
		TInt idx = aFullName.FindC(_L("."));
		if(idx>0){
			aExtendName.Copy(aFullName.Mid(idx+1));
			if ( aExtendName.Compare(aText)==0)
			{
				aAllName.Append(KPath);
				aAllName.Append(aFullName);
				fs.Delete(aAllName);
			}
			aExtendName.Zero();
			aAllName.Zero();
		}
		aFullName.Zero();
	}
}

void CGetAndDelete::ShowDataQueryL(
    const TInt aQueryResourceId,
    const TInt aTextResourceId,
//    const TInt aPromptResoureId,
    const TInt aMaxLength,
//    const TBool aDisplayFlag,
    TDes& aText )
    {
    
    iDisplayDialog = ETrue;

    TBuf<128> textData;

    if ( aTextResourceId )
        {
        iCoeEnv->ReadResourceL( textData, aTextResourceId );
        }
    
    CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL(
        textData, CAknQueryDialog::ENoTone );
    CleanupStack::PushL( dlg );
/*
    if ( aPromptResoureId )
        {
        TBuf<KChatTextBufLength> prompt;
        iCoeEnv->ReadResourceL( prompt, aTextResourceId );
        dlg->SetPromptL( prompt );
        }
*/
    if ( aMaxLength )
        {
        dlg->SetMaxLength( aMaxLength );
        }
        
	  CleanupStack::Pop( dlg );
	  dlg->ExecuteLD( aQueryResourceId );
// 	  TBool answer( dlg->ExecuteLD( aQueryResourceId ) );
/*
    if ( aDisplayFlag && answer )
        {
        HBufC* buffer = HBufC::NewLC( KMessageHeaderLen + 
                                  textData.Length() );

        buffer->Des().Append( '<' );
        buffer->Des().Append( '\t' );
        buffer->Des().Append( textData );
        
        // add the message to the list
        iMessageList->AppendL( *buffer );
        CleanupStack::PopAndDestroy( buffer );
      
        // tell the control about the change
        iListBox->HandleItemAdditionL();
        }
*/
    iDisplayDialog = EFalse;
  
    // get message
    aText = textData;
    
    DrawNow();
    }


// End of File

⌨️ 快捷键说明

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