os.execute("cd ~/ testdir")
configfile = io.open("configfile.cfg", "w")
configfile:write("hello")
configfile:close()
configfile = io.open("~/testdir/configfile.cfg", "w")
But I get the following result:
lua: ifontinst.lua:22: attempt to index global'configfile' (a nil value)
stack traceback:
ifontinst.lua:22: in main chunk
My question is, what is the correct way to use IO.Open to create files in the folder I just created in the user’s home directory?
I appreciate that I made a novice mistake here, so I will apologize if you waste your time.
configfile = io.open(os.getenv("HOME" ).."/testdir/configfile.cfg", "w")
In order to improve the error message, I suggest you use the assert() function to wrap io.open():
configfile = assert( io.open(os.getenv("HOME").."/testdir/configfile.cfg", "w") )
I am writing a Mac OS program, and I have the following lines:
os.execute("cd ~/testdir")
configfile = io.open("configfile.cfg", "w")
configfile:write("hello")
configfile:close()
The problem is that it is only in The configuration file is created in the current directory of the script, not the folder I just entered. I realized this was because I used console commands to change the directory and then instructed Lua code to write the file. To solve this problem, I changed the code to :
configfile = io.open("~/testdir/configfile.cfg", "w")
But I get the following result: p>
lua: ifontinst.lua:22: attempt to index global 'configfile' (a nil value)
stack traceback:
ifontinst.lua:22: in main chunk
My problem is that using IO.Open in the user main What is the correct way to create files in a folder created in a directory?
I appreciate that I made a novice mistake here, so I will apologize if you waste your time.
You There is a problem with the ~ symbol. In your os.execute(“cd~/testdir”) is the shell to interpret the symbol and replace it with your home path. However, in io.open(“~/testdir/configfile.cfg”, “W”), Lua receives the string and Lua does not interpret this symbol, so your program will try to open the file in the incorrect folder. A simple solution is to call os.getenv(“HOME”) and The path string is connected with the file path:
configfile = io.open(os.getenv("HOME").."/testdir/configfile.cfg", "w")
In order to improve the error message, I suggest you use the assert() function to wrap io.open():
configfile = assert( io .open(os.getenv("HOME").."/testdir/configfile.cfg", "w") )
WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3240 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC