1. ホーム
  2. スクリプト・コラム
  3. ルア

ファイル操作のトラバースに関するLuaのコード例

2022-02-11 19:33:42

ファイルのトラバースについて書かれたプログラムスニペットです。

--[[Check all .txt files
For example, if the first row of A.txt has 20 columns, but an extra tab is entered in row X, the output is: Table A has irregularly filled in row X, and there is extra filling at the end of the row
getinfo]]
 
getinfo = io.popen('dir ... //file /b /s')
all = getinfo:read('*all')
 
local filenameList = io.open("filename.txt", "wb")
filenameList:write("Path/n")
filenameList:close()
 
filenameList = io.open("filename.txt", "a")
filenameList:write(all)
io.close(filenameList)
io.close(getinfo)
 
 
local filenameList = tab.Open([[... /filename.txt]], "Path", false)
 
for index, Row in ipairs(filenameList) do
local pathlist = Row["Path"]
local rowString = string.find(pathlist, ".txt")
if rowString ~= nil and rowString ~="" then
moon.CheckRowlength(pathlist, pathlist)
end
end
 
io.popen('dir /b /s') is for windows, obtained by executing command line dir
io.popen('ls') is for linux