sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Helper process with high capability to perform renaming of files or folders for sl@0: // test harnesses. sl@0: // sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: sl@0: sl@0: _LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames sl@0: sl@0: TInt DoRenameFileL(const TDesC& anOld,const TDesC& aNew) sl@0: { sl@0: TInt r = KErrNone; sl@0: RFs fs; sl@0: r = fs.Connect(); sl@0: if (r != KErrNone) sl@0: { sl@0: User::Leave(r); sl@0: } sl@0: CFileMan* fileMan = CFileMan::NewL(fs); sl@0: CleanupStack::PushL(fileMan); sl@0: // Ensure the path exists sl@0: TInt err = fs.MkDirAll(aNew); sl@0: // Make the destination file writeable sl@0: err = fileMan->Attribs(aNew, 0, KEntryAttReadOnly, TTime(0), 0); sl@0: // To process sl@0: err = fileMan->Rename(anOld, aNew); sl@0: RDebug::Print(_L("CFileMan Rename file or folder from %S to %S - err = %d\n"), &anOld, &aNew, err); sl@0: sl@0: CleanupStack::PopAndDestroy(fileMan); sl@0: fs.Close(); sl@0: sl@0: return err; sl@0: } sl@0: sl@0: // Copy the files specified. Format of aFileNames is [srcFile]|[dstFile]. sl@0: static TInt RenameFile(const TDesC& aFileNames) sl@0: { sl@0: TInt pos = aFileNames.Find(KSeparator); sl@0: TFileName srcFile(aFileNames.Mid(0,pos)); sl@0: TFileName dstFile(aFileNames.Mid(pos+1, aFileNames.Length()-(pos+1))); sl@0: sl@0: TRAPD(err,DoRenameFileL(srcFile, dstFile)); sl@0: return err; sl@0: } sl@0: sl@0: sl@0: GLDEF_C TInt E32Main() sl@0: { sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: sl@0: TBuf names; sl@0: User::CommandLine(names); sl@0: TInt err = RenameFile(names); sl@0: delete cleanup; sl@0: return err; sl@0: }