Hi,
I have a code that reads and writes a file in private path of the program's installed directory, however the problem is that its not working when I have installed the program in memory card and it just crashes.
Here is the code that I am using,
------------------------------------
_LIT(KtxDicFileName ,"abc.txt" );
TFileName path;
TFileName pathWithoutDrive;
CEikonEnv::Static()->FsSession().PrivatePath( pathWithoutDrive );
// Extract drive letter into appDrive:
#ifdef __WINS__
path.Copy( _L("c:") );
#else
RProcess process;
path.Copy( process.FileName().Left(2) );
if(path.Compare(_L("c")) || path.Compare(_L("C")))
CEikonEnv::Static()->FsSession().CreatePrivatePath(EDriveC);
else if(path.Compare(_L("e")) || path.Compare(_L("E")))
CEikonEnv::Static()->FsSession().CreatePrivatePath(EDriveE);
#endif
path.Append( pathWithoutDrive );
path.Append( KtxDicFileName );
TInt32 value = -1;
RFs& fileServer = CCoeEnv::Static()->FsSession();
User::LeaveIfError(fileServer.Connect());
RFileReadStream readStream;
TInt err = readStream.Open(fileServer, path, EFileRead);
CleanupClosePushL(readStream);
if(err == KErrNotFound)
{
CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
informationNote->ExecuteLD(_L("File not found , creating"));
value = -1;
RFileWriteStream writeStream;
User::LeaveIfError(writeStream.Replace(fileServer, path, EFileWrite));
writeStream.PushL();
writeStream.WriteInt32L(value);
writeStream.CommitL();
CleanupStack::PopAndDestroy(&writeStream);
}
else if(err == KErrNotFound)
{
CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
informationNote->ExecuteLD(_L("Path not found , creating"));
value = -1;
RFileWriteStream writeStream;
User::LeaveIfError(writeStream.Replace(fileServer, path, EFileWrite));
writeStream.PushL();
writeStream.WriteInt32L(value);
writeStream.CommitL();
CleanupStack::PopAndDestroy(&writeStream);
}
else
{
CAknInformationNote* informationNote = new ( ELeave ) CAknInformationNote;
informationNote->ExecuteLD(_L("File found , reading"));
readStream >> value;
}
CleanupStack::PopAndDestroy(&readStream);
return value;
---------------------------------------------------
I have checked the path variable by printing it on a message box and its fine like, e:\private\uid\file.ext
Can anyone please tell me what am I am doing wrong here, the code works fine when the program is installed in phone memory.

Reply With Quote


