Thread: File I/O Tool
View Single Post
David B
Senior Member
David B's Avatar
Status: Offline
Posts: 1,145
Join Date: Dec 2010
Location: N/A
Default 06-14-2011, 06:44 PM

Originally Posted by arty-fishL View Post
This is a neat file I/O tool I made for TauTrumpsPi.
Import the object into the world you want to use it in.
Don't rename it and don't delete any of its variables, methods or events.

Set IOTool's variable named current_file to the file to be used. Change it when necessary.
Use any of its methods wherever required.
Some methods have basic help/info in comments inside them.
Any method that returns a value (eg read_all or get_lines) will write its value to IOTool's variable named returnString (or returnNumber for get_lines).

Read below only if you require help:

get_value - returns to returnString - parameter value is the name of the value key - returns info about the file (eg size).
new_file - returns none - parameter filename is the complete folder, file,ext name (ie C:\Users\Me\Documents\blank.txt).
new_folder - returns none - parameter dirname is the complete pathname of the directory (ie C:\Users\Me\Documents\folder).
read_all - returns to returnString - no parameters - reads the entire file.
read_line - returns to returnString -parameter line is the line to read - reads only a given line from the file.
get_lines - returns to returnNumber -no parameters - returns the number of lines of text in the file.
write - returns none - parameter text is the string to write with - writes over everything in the file.
write_line - returns none - parameter text is the string to write with, line is the line to write over - writes over everything on only the specified line in the file.
write_append - returns none - parameter text is the string to write with - writes onto the end of the file, retaining any text already in it.
delete_file - returns none - no parameters - completely removes the file from disc.
replace_file - returns none - parameter file_to_overwrite_with is the complete filename of the file to write with - replaces the current file with the contents of another file, replaces in binary, so can replace with images etc.
rename_file - returns none - parameter name is the new name to give the file, set full_path to true to change complete filename; or to false just to change name relative to the director
y it is in - renames the file.
Cool! It looks interesting!
Reply With Quote