Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import std.file;
- import std.string;
- void wrFile(byte command_code) {
- string file_name;
- string file_string;
- string file_buffer;
- if (command_code == 1) {
- write("File name > ");
- file_name = readln().strip();
- if (file_name[$ - 3] != 't' && file_name[$ - 1] != 't') {
- file_name = file_name ~ ".txt";
- }
- write("File string > ");
- file_string = readln().strip();
- File file1 = File(file_name, "w");
- file1.write(file_string);
- file1.close();
- }
- if (command_code == 2) {
- write("File name > ");
- file_name = readln().strip();
- if (file_name[$ - 3] != 't' && file_name[$ - 1] != 't') {
- file_name = file_name ~ ".txt";
- }
- File file1 = File(file_name, "r");
- if (file1.isOpen() == true) {
- writeln("Debug > File opened");
- }
- write();
- file_buffer = file1.readln().strip();
- writeln("File buffer > ", file_buffer);
- file1.close();
- }
- }
- void main() {
- string command;
- while (true) {
- write("Command > ");
- command = readln().strip();
- /*
- Available commands:
- write - 1;
- read - 2;
- */
- if (command[0] == 'w' && command[$ - 1] == 'e') {
- wrFile(1);
- }
- if (command[0] == 'r' && command[$ - 1] == 'd') {
- wrFile(2);
- }
- if (command[0] == 'e' && command[$ - 1] == 't') {
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement