none
Read my own file type RRS feed

  • Question

  • The program i'm writing allows users to create and log into accounts and i've managed all the accounts by storing the account credentials in an individual text document for each account.

    i have one blank txt document which i copy using the file.copyfile operation.

    i then change it to a .joe file using small basic so that you can't just open it and read all the data.

    the problem i have is that small basic seems to be unable to read the file when it is essentially a text document.

    i've used the textwindow as a debugging aid and it just can't use file.readcontents to read everything.

    am i doing something wrong or do small basic's capabilities not stretch that far?

    Monday, April 23, 2012 7:30 PM

Answers

  • Program you wrote works for me too; but I'm still struggling to apply it to my code.

    Hello Joe_molo!

    Perhaps you can understand litdev's example better by using variables for each "ingredient":

    Path     = Program.Directory + "\"
    CopyFrom = "test"
    CopyTo   = "test"
    ExtFrom  = ".txt"
    ExtTo    = ".joe"

    File.CopyFile( Path+CopyFrom+ExtFrom   Path+CopyTo+ExtTo ) '  Creates a copy of CopyFrom as CopyTo inside Path

    TestFile = File.ReadContents( Path+CopyTo+ExtTo )          '  Reads from that copied file

    TextWindow.WriteLine( TestFile )                           '  Displays copied file's contents

    PS: Masquerading a file type, like changing .txt to .joe only protects against very newbie users. It's very trivial to just drag the file into a Notepad type of app!
    Tuesday, April 24, 2012 6:45 AM
    Answerer

All replies

  • It should work.  The following does for me:

    File.CopyFile(Program.Directory+"\test.txt",Program.Directory+"\test.joe")
    testFile = File.ReadContents(Program.Directory+"\test.joe")
    TextWindow.WriteLine(testFile)

    Assuming the file exists where I look for it - in my case in the same Dir as I saved the SmallBasic file (i.e. the location of Program.Directory).

    Try a very simple program like mine, then test the file is copied correctly etc.

    Monday, April 23, 2012 8:00 PM
    Moderator
  • It should work.  The following does for me:

    File.CopyFile(Program.Directory+"\test.txt",Program.Directory+"\test.joe")
    testFile = File.ReadContents(Program.Directory+"\test.joe")
    TextWindow.WriteLine(testFile)

    Assuming the file exists where I look for it - in my case in the same Dir as I saved the SmallBasic file (i.e. the location of Program.Directory).

    Try a very simple program like mine, then test the file is copied correctly etc.

    hmmm, the program you wrote works for me too but i'm still struggling to apply it to my code.

    thanks for the help.

    Monday, April 23, 2012 8:12 PM
  • Program you wrote works for me too; but I'm still struggling to apply it to my code.

    Hello Joe_molo!

    Perhaps you can understand litdev's example better by using variables for each "ingredient":

    Path     = Program.Directory + "\"
    CopyFrom = "test"
    CopyTo   = "test"
    ExtFrom  = ".txt"
    ExtTo    = ".joe"

    File.CopyFile( Path+CopyFrom+ExtFrom   Path+CopyTo+ExtTo ) '  Creates a copy of CopyFrom as CopyTo inside Path

    TestFile = File.ReadContents( Path+CopyTo+ExtTo )          '  Reads from that copied file

    TextWindow.WriteLine( TestFile )                           '  Displays copied file's contents

    PS: Masquerading a file type, like changing .txt to .joe only protects against very newbie users. It's very trivial to just drag the file into a Notepad type of app!
    Tuesday, April 24, 2012 6:45 AM
    Answerer