locked
File.WriteContents writing to hidden files? RRS feed

  • Question

  • I have noticed that File.WriteContents writes to premade files or makes files but i was wondering if there was something that would allow writing to hidden files, is this possible?
    Sunday, April 26, 2015 8:53 AM

Answers

  • I don't know about writing to hidden files but can write to unhidden files inside a Hidden Folder.

    File.WriteContents(Program.Directory + "\hiddenFolder\unhiddenFile.txt" "hello")

    • Marked as answer by [brackets] Monday, April 27, 2015 10:05 AM
    Sunday, April 26, 2015 11:12 AM

All replies

  • I don't know about writing to hidden files but can write to unhidden files inside a Hidden Folder.

    File.WriteContents(Program.Directory + "\hiddenFolder\unhiddenFile.txt" "hello")

    • Marked as answer by [brackets] Monday, April 27, 2015 10:05 AM
    Sunday, April 26, 2015 11:12 AM
  • Consider what you're using hidden files for. They're no good for security.

    At best they're only good for hiding clutter on your own pc.

    Sunday, April 26, 2015 11:23 AM
  • I just tested writing to a hidden file: it works, MSDOS doesn't show the file, but Small Basic "Open file" shows the file and can load it.

    Jan [ WhTurner ] The Netherlands

    Sunday, April 26, 2015 11:31 AM
    Answerer
  • First NOTE what JJ said.

    Supposed a testfile "C:\Program Files\Microsoft\Small Basic\Projects\TestFile.txt"  (here with space(s) in path)

    and a original set attribute of +H for the testfile, you could use:

    '------------- SNIP -------------

    qu = Text.GetCharacter(34)
    txtFile = "C:\Program Files\Microsoft\Small Basic\Projects\TestFile.txt"
    txt = "My Text to write"
    cmdLine = "-H " +qu+ txtFile +qu   '' clears the 'hidden / H' attribute only
    cmdLine = qu+ cmdLine +qu

    LDProcess.Start("attrib.exe", cmdLine)
    res = File.WriteContents(txtFile, txt)

    TextWindow.WriteLine(res)

    ' -------- SNAP -----------

    Depending on the set attributes (can be checked with

    attr = LDShell.GetDetail(txtFile, 6)  '' or
    'attr2 = LDShell.GetDetail(txtFile, "Attributes")  ' on an engl. System

    )

    you will have to ev. temporary set back others as well. eg. 'attrib.exe -H -S -R txtFile',

    remember the original attribute(s) and, after writing to txtFile, set back again (eg. attrib.exe +H +S +R txtFile) to the original attributes.

    PS: If you are on SB 1.0 there is Data extension's 'FilePlus' object, which supports some methods for attributes (like .ContainsAttiribute, AddAttiribute, RemoveAttiribute). Perhaps further ('old') extensions that support attributes (like 'Fremy' etx ?? etc), but unfortunaltely the don't work any more for SB 1.1.

    At any rate: You should KNOW what you are doing !!

    Sunday, April 26, 2015 11:46 AM
    Answerer