×

Discussion Board

Results 1 to 13 of 13
  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    5

    Problem opening file from a dynamic path

    Hi...

    Right now, I'm trying to open a file with a dynamic path. The dynamic path is stored in a text file. But I can't open the file.

    here's my code:

    Code:
    /// I open the text file first, this file contain a path to another file
    RFs fsDbSession;
    User::LeaveIfError(fsDbSession.Connect());
    _LIT(KFilenameVoiceDb2,"e:\\smstospeech\\db\\voicedb2.txt");
    RFile fileVoiceDb2;
    User::LeaveIfError(fileVoiceDb2.Open(fsDbSession,KFilenameVoiceDb2,EFileRead));
    TFileText fileVoiceDbRead2;
    fileVoiceDbRead2.Set(fileVoiceDb2);
    
    // Then I read the text file and put the text to a TBuf
    // The text is like this: E:\\smstospeech\\pcm\\_e.pcm
    TBuf<50> tempBufVoiceDb2;
    fileVoiceDbRead2.Read(tempBufVoiceDb2);
    
    // Then I try to open the file
    _LIT(KVoiceFileOK,"open Voice File OK");
    RFile voiceFile;
    if(voiceFile.Open(fsDbSession,tempBufVoiceDb2,EFileRead)==KErrNone)
    {
    iLogView->DrawTextL(KVoiceFileOK); //View the KVoiceFileOK
    }

    I couldn't open the file. But, if I change the path to a hardcoded path to _LIT(KMyVoiceFile,"E:\\smstospeech\\pcm\\_e.pcm");
    The file is normally opened. And when I read the Series 60 SDK's help, the filename should be in const TDesc& filename. So, I create a non modifiable buffer and put the path there.

    Code:
    TBufC<50> filePath;
    filePath = tempBufVoiceDb2;
    
    // then I try to open the file again
    _LIT(KVoiceFileOK,"open Voice File OK");
    RFile voiceFile;
    if(voiceFile.Open(fsDbSession,filePath,EFileRead)==KErrNone)
    {
    iLogView->DrawTextL(KVoiceFileOK); //View the KVoiceFileOK
    }
    But I still couldn't open the file. Is there any solution? Thanks alot guys...




    Regards
    Fakhrudin

  2. #2
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,143

    Re: Problem opening file from a dynamic path

    maybe you could try reading directly with the fileVoiceDb2 RFile object.

    you could also try to write the filename back to a file to see the text that you are actually getting. Or use Global notes to give you some run-time feedback during debugging.

    yucca

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    5

    Re: Problem opening file from a dynamic path

    Thanks alot Yucca. I've tried to compare the text (file path) from the hardcoded _LIT(KMyVoiceFile,"E:\\smstospeech\\pcm\\_e.pcm"); And from the one from the text file. Both of them shows the exact same text E:\\smstospeech\\pcm\\_e.pcm.

    Is there any chance that I use a filename in a TBuf to open a file, or the filename should always use _LIT?


    Regards

    Fakhrudin

  4. #4
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,143

    Re: Problem opening file from a dynamic path

    It should not matter whether it is contant literal or dynamic buffer, only thing it cares about that it has the drive+path+name+extension correctly set. Maybe there are some non-visible characters in there... You could try getting rid of them by using TrimAll() maybe.

    yucca

  5. #5
    Regular Contributor
    Join Date
    Apr 2007
    Location
    beijing,china
    Posts
    496

    Re: Problem opening file from a dynamic path

    must be the tubf wrong.
    tbuf can be the file name. not need the tbufc.
    you can first do tbuf.fillZ() to set the tbuf before using.
    and step by step debug to see the diff of the content of that two tbuf.
    heaven or dell? survival or death?

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,567

    Re: Problem opening file from a dynamic path

    Quote Originally Posted by didienGanteng
    Thanks alot Yucca. I've tried to compare the text (file path) from the hardcoded _LIT(KMyVoiceFile,"E:\\smstospeech\\pcm\\_e.pcm"); And from the one from the text file. Both of them shows the exact same text E:\\smstospeech\\pcm\\_e.pcm.
    They should not. At least the hardcoded text should become unescaped (single-backslashed). I do not know if it matters, but you can try what happens if you put single-backslashes to voicedb2.txt.

  7. #7
    Registered User
    Join Date
    Oct 2006
    Posts
    5

    Talking Re: Problem opening file from a dynamic path

    Thanks alot Yucca, Isarc, Hu. My problem is solved.

    At first, I try to append the _LIT to a TBuf, and still the file opened correctly. So, just like what Isarc said, TBuf is not the problem. Then, I try to view the _LIT variable and all the double-blackslashed is altered by a single-blackslashed.

    When I view this
    _LIT(KFilenameVoiceDb2,"e:\\smstospeech\\db\\voicedb2.txt");
    it only shows e:\smstospeech\db\voicedb2.txt.

    So I change all the path with only a single blackslashed. And it works perfectly. Thanks you guys. But I still wonder how could that happen? Is it the writing rules?


    Regards

    Fakhrudin

  8. #8
    Regular Contributor
    Join Date
    Apr 2007
    Location
    beijing,china
    Posts
    496

    Re: Problem opening file from a dynamic path

    you can use
    _LIT(KFileName, "c:\\test\\test.txt");
    TBuf<24> vFileName(KFileName);
    to be the file name.
    i can't understand why the single blackslashed can work. once , i forgot add two blackslashed, error happened.
    heaven or dell? survival or death?

  9. #9
    Registered User
    Join Date
    Oct 2006
    Posts
    5

    Re: Problem opening file from a dynamic path

    Yup... You're right Isark.

    _LIT(KFileName, "c:\\test\\test.txt");
    TBuf<24> vFileName(KFileName);

    Is also work perfectly. The file can be opened normally...

    Then, I try to view the vFileName variable. It only show c:\test\test.txt though I wrote it with double-slashed. Weird isn't it... Or maybe someone can explain this.

    From this problem, I realized that we should use double-backslashed in literal type file path (e.g _LIT(KFileName, "c:\\test\\test.txt");). But when we use a dynamic path just like what I did (the path to a file is inside a text file) we should write the path (inside the text file) in single-backslashed (e.g c:\test\test.txt).

    Thanks for your support.


    Regards

    Fakhrudin

  10. #10
    Regular Contributor
    Join Date
    Apr 2007
    Location
    beijing,china
    Posts
    496

    Re: Problem opening file from a dynamic path

    It only show c:\test\test.txt though I wrote it with double-slashed.
    oh, do you know c++?
    heaven or dell? survival or death?

  11. #11
    Registered User
    Join Date
    Oct 2006
    Posts
    5

    Re: Problem opening file from a dynamic path

    I'm a C++ and Symbian newbie. So sorry if it's just C++ basic... I should learn alot then....


    Thanks Isarc

  12. #12
    Regular Contributor
    Join Date
    Apr 2007
    Location
    beijing,china
    Posts
    496

    Re: Problem opening file from a dynamic path

    my words is discourteous, sorry.
    heaven or dell? survival or death?

  13. #13
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Budapest, Hungary
    Posts
    28,567

    Re: Problem opening file from a dynamic path

    Check for example http://www.samspublishing.com/articl...&seqNum=8&rl=1 or http://msdn2.microsoft.com/en-us/library/ms860944.aspx
    So if you need a single \ character in a C/C++/Java/C#/etc. source code, you have to use \\, since this sequence is going to be converted to a single \ character.
    But in files that are not source code (like your voicedb2.txt), you should use a single \, since DOS/Windows/Symbian/etc. paths use a single \ as separator (although many tools accept arbitrary ammount of \-s).

Similar Threads

  1. [moved] Theme Studio Error
    By TalJ in forum Themes/Carbide.ui
    Replies: 2
    Last Post: 2009-09-06, 03:39
  2. Problem with .mbg file
    By ticktock in forum Symbian User Interface
    Replies: 3
    Last Post: 2007-03-26, 22:05
  3. Problem in playing in an audio file.
    By PankajNeve in forum Symbian C++
    Replies: 3
    Last Post: 2007-03-09, 13:52
  4. Replies: 4
    Last Post: 2006-08-23, 11:04
  5. Nokia Image Converter
    By davidpurdie in forum General Development Questions
    Replies: 0
    Last Post: 2004-02-18, 15:31

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •