Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not params or params.len < 1 or params.len > 2 then exit("<b>Example:</b> bankparser [folder] (outFile)")
- myComputer = get_shell.host_computer
- banksFolderPath = params[0]
- if banksFolderPath[0] != "/" then banksFolderPath = myComputer.current_path + "/" + banksFolderPath
- //Check folder//
- banksFolder = myComputer.File(banksFolderPath)
- if not banksFolder then exit("<b>Folder <i>'" + banksFolderPath + "'</i> not found</b>")
- if not banksFolder.is_folder then exit("<b>The path <i>'" + banksFolderPath + "'</i> does not indicate a folder</b>")
- banks = banksFolder.get_files
- if banks.len == 0 then exit("<b>Folder <i>'" + banksFolderPath + "'</i> contains no files</b>")
- //Check outFilePath//
- if params.len == 2 then
- if params[1] == "/" then exit("<b>Wrong path - <i>'" + params[1] + "'</i></b>")
- if params[1][0] == "/" then
- outFileParentPath = parent_path(params[1])
- if outFileParentPath == "/" then
- outFileDirPath = ""
- else
- outFileDirPath = parent_path(params[1])
- end if
- else
- outFileDirPath = myComputer.current_path + "/" + parent_path(params[1])
- end if
- outFileName = params[1]
- if outFileName[-1] == "/" then outFileName = outFileName[:-1]
- outFileName = outFileName.split("/")[-1]
- else
- outFileDirPath = banksFolderPath
- outFileName = "Banks.txt"
- end if
- outFilePath = outFileDirPath + "/" + outFileName
- //Check outFile//
- outFile = myComputer.File(outFilePath)
- if outFile then
- outFile.set_content("")
- else
- outFileDir = myComputer.File(outFileDirPath)
- if not outFileDir then exit("<b>Could not create file on path - <i>'" + outFilePath + "'</i></b>")
- myComputer.touch(outFileDirPath, outFileName)
- outFile = myComputer.File(outFilePath)
- if not outFile then exit("<b>Could not create file on path - <i>'" + outFilePath + "'</i></b>")
- end if
- //Parsing//
- for bank in banks
- if bank.path == outFile.path then
- banks.remove(banks.indexOf(bank))
- else
- outFile.set_content(outFile.content + bank.content + "\n")
- end if
- end for
- outFile.set_content(outFile.content[:-1])
- print("[Parsed " + banks.len + " files to '" + outFilePath + "']")
- print("[Total accounts - " + outFile.content.split("\n").len + "]")
Add Comment
Please, Sign In to add comment