Can't resolve FolderItems and Native Path

Not sure what I’m doing wrong. Trying to make a series of folders and text files on a network share, based on fields the user will fill in.

Making the folders was easy, but when using textstream to create the text file, Im getting NilObjectException errors. I’ve done this in the past with SpecialFolders, but I can’t seem how to get it to work with paths that are strings. The variable “Path” in this snippet is a network URL I have defined earlier.

dim DOC_PATH as string DOC_PATH =path + "\\2_Doc" Dim DN As FolderItem DN = GetFolderItem(DOC_PATH +"\\Deployment_notes.txt") Dim t as TextOutputStream t = TextOutputStream.Append(DN) t.Writeline(DEPLOYMENT_TEXTAREA.text) t.Close

try
DN = GetFolderItem(DOC_PATH +"\Deployment_notes.txt", Folderitem.PathTypeNative)

That gives me an IOexception.

ioexception means more like that your path isnt referring to the file the in way you think
like “this file does not exist”
but I can debug that from here
you will have to put in a break point in there & see why that might be happening

Nothing gleamed from breakpoint. DN resolving as it should.

DN’s properties for exists etc are all true ?
An IOException could result from not having permissions
but you’d have to look in the IOException object to know if there is any such message or error code

Lots of false results. Exists is false, but that’s OK, as TextStream will create the text file. At least it does with special folders.

All of the folder paths are there…they are always created prior to this portion of the code.

Not sure why this is so stubborn. Here is the same thing from a program I wrote a file back. It uses special folders, and works flawlessly.

[code] Dim Documents As FolderItem = SpecialFolder.Temporary.child(“AutoIT Maker”)
Dim f As FolderItem = Documents.Child(“Untitled.au3”)
Dim t as TextOutputStream

If f <> Nil then
f.delete
t = TextOutputStream.Append(f)
t.Writeline(MAIN.SCRIPT_TEXTAREA.text)
t.Close
end[/code]

So I basically am trying to use the equivalent with a shell path.

Edited code for API2.0 below.

You forgot to Create the TextOutputStream?
Or open if if already exists and want to append to

dim DOC_PATH as string DOC_PATH =path + "\\2_Doc" Dim DN As FolderItem DN = GetFolderItem(DOC_PATH +"\\Deployment_notes.txt") Dim t as TextOutputStream t = TextOutputStream.Open(DN) t.Writeline(DEPLOYMENT_TEXTAREA.text) t.Close

http://documentation.xojo.com/api/files/textoutputstream.html#textoutputstream-create
http://documentation.xojo.com/api/files/textoutputstream.html#textoutputstream-open

TextOutputStream .Open(Folderitem)
Will create the file if it does not exists

TextOutputStream.Append(DN) (Api1.0) should do that same thing as .Open(DN) does (API2.0)
Not sure why it doesn’t work, perhaps the Network drive is busy or inaccessible ?

That gives and error that the item doesn’t exist. The “TextopenStream.open(DN)” line.

See edit above. .Append() is for API1.0 and .Open() is for API2.0
What xojo version do you use? And which platform ?

2016 relese 3

And the network drive is not busy and I have full access.

The folders are created each time, no issues. It’s the damn text file…

You may want to set the

GetFolderItem(path As String, Optional pathMode As Integer) As FolderItem

PathMode to something that works

or try

  dim DOC_PATH as string
  Dim DN As FolderItem
#If targetWindows 
  DOC_PATH =path + "\\2_Doc" 
  DOC_PATH = DOC_PATH.ReplaceAll("\","/")
  DN = GetFolderItem(DOC_PATH +"/Deployment_notes.txt")
#else
  DOC_PATH =path + "\\2_Doc" 
  DN = GetFolderItem(DOC_PATH +"\\Deployment_notes.txt")
#endif

  Dim t as TextOutputStream
  t = TextOutputStream.Append(DN)
  t.Writeline(DEPLOYMENT_TEXTAREA.text)
  t.Close

Again which platform? Windows, MacOS, Linux ?

The NilObjectException tells me eighter the DN = Nil or t = Nil.
Does the debugger show you which one is nil in the variables ?

Windows

Says DN and T are nil. This is on my original code.

Tried your last code just now…same nil for DN and T

I never do Open unless I’m sure the folderitem already exists. If it doesn’t, then I use this:

dim bs as BinaryStream = BinaryStream.Create(TheFolderItem, False)

That’s odd, did you try to set the pathMode ?
can you copy and paste the Exact string that is ending up in DN, that is the DOC_PATH variable.
Also try to paste that exact string (resulting from debugger) into the windows explorer filepath bar. You’ll see if it points to the right direction.