<commit_before>require "lfs"

export class file
	@Read: (path, mount using nil) ->
		f = io.open path
		f\read "*a"

	@Find: (pathPattern, mount, sorting using nil) ->
		files = {}
		folders = {}

		posLastSlash = -(pathPattern\reverse!\find("/") or 0)
		path = pathPattern\sub 1, posLastSlash
		path = "./" if path == ""
		searchPattern = pathPattern\sub posLastSlash+1
		searchPattern = searchPattern\gsub("*", ".*", 1, true)\gsub(".", "\.", 1, true) -- To use in RegEx

		for file in lfs.dir path
			if file\find searchPattern
				if lfs.attributes(path .. "/" .. file, "mode") == "file"
					table.insert files, file
				elseif file ~= ".." and file ~= "."
					table.insert folders, file

		return files, folders<commit_msg>Fixed a bug with the filesystem mock in different Lua implementations.<commit_after>require "lfs"

export class file
	@Read: (path, mount using nil) ->
		f = io.open path
		f\read "*a"

	@Find: (pathPattern, mount, sorting using nil) ->
		files = {}
		folders = {}

		posLastSlash = -(pathPattern\reverse!\find("/") or 0)
		path = pathPattern\sub 1, posLastSlash
		path = "./" if path == ""
		searchPattern = pathPattern\sub posLastSlash+1
		searchPattern = searchPattern\gsub("*", ".*", 1, true)\gsub("\\.", "\\.", 1, true) -- To use in RegEx

		for file in lfs.dir path
			if file\find searchPattern
				if lfs.attributes(path .. "/" .. file, "mode") == "file"
					table.insert files, file
				elseif file ~= ".." and file ~= "."
					table.insert folders, file

		return files, folders
{'fraction_non_alphanumeric': 0.16469038208168643, 'fraction_numerical': 0.006587615283267457, 'mean_word_length': 3.029177718832891, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7430547', 'n_tokens_mistral': 580, 'n_tokens_neox': 500, 'n_words': 155}