syslibsapitest/syslibssvs/common/src/TPDeleteFileUtility.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <f32file.h>
       
    21 #include <e32debug.h>
       
    22 
       
    23 
       
    24 TInt DoDeleteFileL(const TDesC& aFileName)
       
    25 	{
       
    26 	RFs			fs;
       
    27 	User::LeaveIfError(fs.Connect());
       
    28 	CleanupClosePushL(fs); 
       
    29 	CFileMan*	fileMan = CFileMan::NewL(fs);
       
    30 	CleanupStack::PushL(fileMan); 
       
    31 
       
    32 	// Make the destination file writeable 
       
    33     TInt	err = fileMan->Attribs(aFileName, 0, KEntryAttReadOnly, TTime(0), 0);
       
    34 
       
    35 	// To process 
       
    36     err = fileMan->Delete(aFileName);
       
    37     RDebug::Print(_L("CFileMan Delete file %S - err = %d\n"), &aFileName, err);
       
    38 
       
    39 	CleanupStack::PopAndDestroy(2, &fs);
       
    40 
       
    41 	return err;
       
    42 	}
       
    43 
       
    44 // Delete the file specified.
       
    45 static TInt DeleteFile(const TDesC& aFileName)
       
    46 	{	
       
    47 	TFileName	fileName(aFileName);
       
    48 
       
    49 	fileName.TrimLeft();
       
    50 	fileName.TrimRight();
       
    51 
       
    52 	TRAPD(err,DoDeleteFileL(fileName));
       
    53 	return err;
       
    54 	}
       
    55 
       
    56 
       
    57 GLDEF_C TInt E32Main()
       
    58 	{
       
    59 	CTrapCleanup*			cleanup =	CTrapCleanup::New(); 
       
    60 	
       
    61 	TBuf<KMaxFileName>	name;
       
    62 	User::CommandLine(name);
       
    63 	TInt					err = DeleteFile(name);
       
    64 	delete cleanup;
       
    65 	return err;
       
    66 	}