Skip to content
Snippets Groups Projects
Commit a8997420 authored by Abhay Menon's avatar Abhay Menon
Browse files

Merge branch 'main' into '33-set-up-launch-from-command-line'

parents 013c82e9 83aa282d
No related branches found
No related tags found
1 merge request!2Resolve "Set up launch from command line"
Pipeline #83487 passed
...@@ -38,13 +38,13 @@ fun main(args: Array<String>) { ...@@ -38,13 +38,13 @@ fun main(args: Array<String>) {
} else { } else {
if (args.size < 2) { if (args.size < 2) {
val filename = args[0] val filename = args[0]
// Optional Regex Check for a specific argument format: // Optional Regex Check for a specific argument format:
MessageUtils.verifyFilename(filename, Regex("^.*[.](md|txt)$")) MessageUtils.verifyFilename(filename, Regex("^.*[.](md|txt)$"))
// if (fileExists) { // if (fileExists) {
// Filemanager(".").editfile() // Filemanager(".").editfile()
// } else { // } else {
// Filemanager(".").createfile() // Filemanager(".").createfile()
// } // }
} else { } else {
if (args[0] != "-d") { if (args[0] != "-d") {
throw IllegalArgumentException("[ERROR]: First parameter must be the delete flag") throw IllegalArgumentException("[ERROR]: First parameter must be the delete flag")
...@@ -61,5 +61,4 @@ fun main(args: Array<String>) { ...@@ -61,5 +61,4 @@ fun main(args: Array<String>) {
} }
} }
} }
} }
package notes.multi.utilities package notes.multi.utilities
import java.io.File import java.io.File
import java.io.FileInputStream import java.io.InputStream
import java.util.*
import kotlin.io.path.exists
class Filemanager(val dir: String) {
private val directory = File(dir)
fun files() : MutableList<File> { class Filemanager(private val dir: String, private val name: String) {
val retfiles = mutableListOf<File>() private val directory = File(dir)
private val filepath = File("$dir/$name")
private val listfiles = mutableListOf<File>()
init {
for (f in directory.listFiles()!!) { for (f in directory.listFiles()!!) {
if (f.extension == "txt" || f.extension == "md") { if (f.extension == "txt" || f.extension == "md") {
retfiles.add(f) listfiles.add(f)
} }
} }
return retfiles
} }
//returns list of files
fun files() : MutableList<File> {
return listfiles
}
// create and write to that file
fun writefile(line:String) {
filepath.writeText(line)
listfiles.add(filepath)
}
// opens and read the existing file
fun openfile(): String {
if (!listfiles.contains(filepath)) {
return ""
}
val inputStream: InputStream = filepath.inputStream()
fun createfile() { return inputStream.bufferedReader().use { it.readText() }
//TODO: Create File
} }
fun deletefile(path:String) { fun deletefile():Boolean {
//TODO: DELETE FILE listfiles.remove(filepath)
return filepath.delete()
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment