File IO, Syntax for network file path access

Posted by Fletchling on Sat 02 Dec 2006 09:49 PM — 11 posts, 31,635 views.

Australia #0
Using various IO functions, I'd like to access a file stored on a network drive.

Currently, I have a file called (for instance) sw.txt in the default folder MC accesses for logs and so on. This works well, but is only local.

using something like;
***script lines***
for line in io.lines ("sw.txt") do
print (line)
***more script lines***


The file(s) in question may be stored on a server called "aardsp" in a folder called "texthelps", so the path is \\aardsp\texthelps\sw.txt. I've tried a number of combinations but I can't get the IO function to get the file from anywhere other than the local file, ideas very much appreciated.


USA #1
Lua's IO probably doesn't support opening network paths.

Try mapping a network drive so that you can get a proper drive-based path. Then Lua will probably be happier with it.
Australia #2
Sure mapping the drive will help, but I still can't explicitly direct mush to consistently grab a file from any directory other than that currently the default.. even somewhere on local c:\...somewhere.

I should have been clearer in the original question...
USA #3
Oh, so you can't get any other path?

Are you properly escaping your backslashes? Something like \t means a literal tab; if you want to say, e.g., c:\tmp you have to write c:\\tmp.
Australia #4
Assuming a file at C:\text\sw.txt

using io function (first line only here);
for line in io.lines ("C:\\text\\sw.txt") do


gives this error;
[string "Alias: "]:1: bad argument #1 to 'lines' (C: extsw.txt: Invalid argument)
stack traceback:
[C]: in function 'lines'
[string "Alias: "]:1: in main chunk

I'm missing something obvious I'm sure, appreciate your help again.
USA #5
for line in io.lines("c:\\tmp\\delete_me\\phil-151-defs.txt") do
    print(line)
end

That worked for me, but outside of MUSHclient.

You can also try double-escaping, because MUSHclient might be processing one level of escaping. Try \\\\ instead of just \\.



EDIT: added double escaping.
Amended on Sun 03 Dec 2006 02:18 AM by David Haley
Australia #6
Note in the previous post, I'd used \\ instead of \.
**stumped for now**
USA #7
Oops. Looks like the forum escaped the slashes for me... I edited my post and fixed it. Please look at it again.
Australia #8
Awesome, 4 backslashes works, thanks Ksilyan.

Now snugglepot and cuddlepie can share the same map, quest and speedwalk files, she'll be happy about that.
Australia Forum Administrator #9
You can save a lot of backslashes by using forward slashes, that seems to work:


for line in io.lines ("c:/tmp/delete_me/foo.txt") do
    print(line)
end
USA #10
Yes, indeed, Windows also is happy taking forward slashes. I probably should have mentioned that. :-)