lowlevellibsandfws/pluginfw/Framework/EcomTestUtils/t_processfilemanrename.cpp
changeset 0 e4d67989cc36
child 44 97b0fb8a2cc2
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Helper process with high capability to perform renaming of files or folders for
       
    15 // test harnesses. 
       
    16 // 
       
    17 //
       
    18 
       
    19 #include <f32file.h>
       
    20 #include <e32debug.h>
       
    21 
       
    22 
       
    23 _LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames
       
    24 
       
    25 TInt DoRenameFileL(const TDesC& anOld,const TDesC& aNew)
       
    26 	{
       
    27 	RFs fs;
       
    28 	fs.Connect();
       
    29 	CFileMan* fileMan = CFileMan::NewL(fs);
       
    30 	CleanupStack::PushL(fileMan); 
       
    31 	// Ensure the path exists
       
    32 	TInt err = fs.MkDirAll(aNew);	
       
    33 	// Make the destination file writeable 
       
    34     err = fileMan->Attribs(aNew, 0, KEntryAttReadOnly, TTime(0), 0);
       
    35 	// To process 
       
    36     err = fileMan->Rename(anOld, aNew);
       
    37     RDebug::Print(_L("CFileMan Rename file or folder from %S to %S - err = %d\n"), &anOld, &aNew, err);
       
    38     
       
    39 	CleanupStack::PopAndDestroy(fileMan); 
       
    40     fs.Close();
       
    41 
       
    42 	return err;
       
    43 	}
       
    44 	
       
    45 // Copy the files specified.  Format of aFileNames is [srcFile]|[dstFile].
       
    46 static TInt RenameFile(const TDesC& aFileNames)
       
    47 	{	
       
    48 	TInt pos = aFileNames.Find(KSeparator);
       
    49 	TFileName srcFile(aFileNames.Mid(0,pos));
       
    50 	TFileName dstFile(aFileNames.Mid(pos+1, aFileNames.Length()-(pos+1)));
       
    51 			
       
    52 	TRAPD(err,DoRenameFileL(srcFile, dstFile));
       
    53 	return err;
       
    54 	}
       
    55 
       
    56 
       
    57 GLDEF_C TInt E32Main()
       
    58 	{
       
    59 	CTrapCleanup* cleanup =	CTrapCleanup::New(); 
       
    60 	
       
    61 	TBuf<KMaxFileName*2> names;
       
    62 	User::CommandLine(names);
       
    63 	TInt err = RenameFile(names);
       
    64 	delete cleanup;
       
    65 	return err;
       
    66 	}