This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
MarioBG's profile picture

Creating file with "/" in its filename

Started by MarioBG, 31 January 2014 - 10:54 AM
MarioBG #1
Posted 31 January 2014 - 11:54 AM
Hello, I've been recently working on something for college, a Trivial, and found a major issue: I'm using the question name as question filenames, and have found I can't work around the "/" usage for folder recognition. This wouldn't be a problem if we didn't have to ask for a conversion of watts per second, which has to be abbreviated to "W/s".
  • One solution would be another means of question storage which stored the question and the 3 or 4 answers, indicating which is correct, and which could handle 6 categories and 3 question classifications (options, Open Numeric Answer or Open Text Answer)
  • Another one would be a way to work around this character and substituting it somehow
  • Another one would be being able to actually put the character in the file name and reading it afterwards
If you know how to do any of these things, please let me know. Thanks!
surferpup #2
Posted 31 January 2014 - 12:23 PM
Do you really need "/" in the file name? The forward slash is a reserved name in the file system, and I am not aware of a work around for that.

If you are truly committed to the file-system-as-a-database concept you have outlined, you will have to come up with a replacement character for the forward slash, and everytime you print the filename string, you will have to perform the substitution before output.

For example, you could use two caret symbols ("^^") to server as a placeholder for the forward slash. Then use string.gsub to substitute back and forth:


myFileName = "My^^Cool^^File"
changed = string.gsub(myFileName,"%^^","/")
changedBack = string.gsub(myFileName,"%/","^^")

print ("Original: " .. myFileName)
print ("Changed: " .. changed)
print ("Changed Back: " .. changedBack)

Run that code and play with it.
Lyqyd #3
Posted 31 January 2014 - 12:23 PM
I don't have any recommendations for what your best option is, but the forward slash character is an illegal character for file names in every major operating system I can think of, so putting it into the file name is simply not an option.
surferpup #4
Posted 31 January 2014 - 12:48 PM
What about a question and answers table stored under category names? For Example:


QATable = {
	Antlers = {
		Questions = {
			{
				Question = "How many points on a three point deer?",
				Answers={
				   "One",
				   "Two",
				   "Four, the first one is not a point",
				   "Three"
			   },
			   CorrectAnswer = 4
			 },
			 {
				Question = "If Mary had a little lamb, did it have antlers?",
				Answers={
					"Yes",
					"No",
					"No, but the spider did."
				},
				CorrectAnswer = 2
			 },
		}		
	},
	RocketScience = {
		Questions = {
			{   Question = "If you set a match to gasoline, will it explode?",
				 Answers={
					"Of course, it doesn't take a rocket scientist to know that.",
					"If the match is not in a highly oxidative state, probably not."
				},
				 CorrectAnswer = 2
			 },
			 {
				Question = "Can you fly a kite with string theory??",
				Answers={
					"Yes",
					"No",
					"Yes, and it will wash your car."
				},
				CorrectAnswer = 3
			 },
		}

	},
}
Edited on 31 January 2014 - 01:14 PM