Hello Guest it is July 16, 2019, 02:58:02 AM

Author Topic: File Fuction (File Operations) module for txt files  (Read 2129 times)

0 Members and 1 Guest are viewing this topic.

Offline poppabear

*
  • *
  •  2,231 2,231
  • Briceville, TN, USA
    • View Profile
    • S S Systems, LLC
File Fuction (File Operations) module for txt files
« 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

Commercial Mach3 & Mach 4, Design/Build/Retrofit CNC and Industrial machines.
http://www.ss-systems-llc.com/
Re: File Fuction (File Operations) module for txt files
« Reply #1 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"