|
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 _LIT(KSeparator, "|"); // Invalid filepath char used to separate filenames |
|
25 |
|
26 TInt DoCopyFileL(const TDesC& aOld,const TDesC& aNew) |
|
27 { |
|
28 RFs fs; |
|
29 User::LeaveIfError(fs.Connect()); |
|
30 CleanupClosePushL(fs); |
|
31 CFileMan* fileMan = CFileMan::NewL(fs); |
|
32 CleanupStack::PushL(fileMan); |
|
33 |
|
34 // Ensure the path exists |
|
35 TInt err = fs.MkDirAll(aNew); |
|
36 |
|
37 // Make the destination file writeable |
|
38 err = fileMan->Attribs(aNew, 0, KEntryAttReadOnly, TTime(0), 0); |
|
39 |
|
40 // To process |
|
41 err = fileMan->Copy(aOld, aNew, CFileMan::EOverWrite); |
|
42 RDebug::Print(_L("CFileMan Copy file %S to %S - err = %d\n"), &aOld, &aNew, err); |
|
43 |
|
44 CleanupStack::PopAndDestroy(2, &fs); |
|
45 |
|
46 return err; |
|
47 } |
|
48 |
|
49 // Copy the files specified. Format of aFileNames is [srcFile]|[dstFile]. |
|
50 static TInt CopyFile(const TDesC& aFileNames) |
|
51 { |
|
52 TInt pos = aFileNames.Find(KSeparator); |
|
53 TFileName srcFile(aFileNames.Mid(0,pos)); |
|
54 TFileName dstFile(aFileNames.Mid(pos+1, aFileNames.Length()-(pos+1))); |
|
55 |
|
56 srcFile.TrimLeft(); |
|
57 srcFile.TrimRight(); |
|
58 dstFile.TrimLeft(); |
|
59 dstFile.TrimRight(); |
|
60 |
|
61 TRAPD(err,DoCopyFileL(srcFile, dstFile)); |
|
62 return err; |
|
63 } |
|
64 |
|
65 |
|
66 GLDEF_C TInt E32Main() |
|
67 { |
|
68 CTrapCleanup* cleanup = CTrapCleanup::New(); |
|
69 |
|
70 TBuf<KMaxFileName*2> names; |
|
71 User::CommandLine(names); |
|
72 TInt err = CopyFile(names); |
|
73 delete cleanup; |
|
74 return err; |
|
75 } |