Machsupport Forum

Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: poppabear on June 10, 2014, 04:24:48 PM

Title: File Fuction (File Operations) module for txt files
Post by: poppabear on June 10, 2014, 04:24:48 PM
File Functions Module user’s guide.
This module simplifies doing file functions, all files are in .txt extension.
To use the example code, make sure you have a C:\Mach4Hobby\Modules folder
You will need to put the:  FileFuncModule.mcc and the FileFuncTest.mcs in there.
I recommend stepping through the test file, it has error checking to Mach Err.

This header goes in the screen load section if using in screens,
Or it goes at the top of Macros or Wizards

--////////////////  This is the REQUIRED Header code, Begin  //////////////////////
package.path = "./?.lua;c:/Mach4Hobby/Modules/?.mcc;" --where the module file is.   
ff = require "FileFuncModule";--load the module file, call it ff
--///////////////  This is the REQUIRED Header code, End   ///////////////////////

Functions:
Read a file
local contents = ff.FileRead(StrFileName);
--param1 is string path to file with file name
--returns the complete file contents into a string buffer, that you can parse
--with other lua functions like io.line() etc.

Make a NEW file   
ff.FileNew(StrFileName, StrFileContents);--make new file
--param1 is string path to file with file name
--param2 is string buffer that is the contents you want written to the file

Append data to a file
ff.FileApp(StrFileName, StrAppFileContents);--Append to new file
--param1 is string path to file with file name
--param2 is string buffer that is the contents you want appended
--to the end of the file
 
Clear/Erase ALL data that is in the file     
ff.FileClear(StrFileName);--erase contents of file
--param1 is string path to file with file name

Delete the file     
ff.FileDelete(StrFileName)--delete the file

Title: Re: File Fuction (File Operations) module for txt files
Post by: kane17752 on June 13, 2017, 06:36:31 PM
This does not seem to be working in ver 3390.  My path is Mach4Hobby3390\Modules.  This errors out on the require - version mismatch in precompiled chunck.
Code: [Select]
local inst = mc.mcGetInstance()
local profile = mc.mcProfileGetName(inst)
local path = mc.mcCntlGetMachDir(inst)
package.path = path .. "\\Profiles\\" .. profile .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.lua;" .. path .. "\\Modules\\?.mcc;"


--CustFunc Module
package.loaded.mcTouchOff = nil
package.loaded.FileFuncModule = nil
ff = require "FileFuncModule"