My programs issues

pascal111 judas.the.messiah.111 at gmail.com
Fri Aug 12 02:05:46 UTC 2022


This is a program for duplicating files, I made some changes on 
it, and liked to share it may that I get a new advice on it:

'''D

module main;

// D programming language

import std.stdio;
import std.string;
import std.algorithm;
import dcollect;

int main(string[] args)
{

string s;
//char[] f;
string f1, f2, f3;

for(size_t i=0; args[1].strmid(i, 1)!="."; i++)
        f1~=args[1].strmid(i, 1);


for(size_t i=args[1].length-1; args[1].strmid(i, 1)!="."; i--)
        f2~=args[1].strmid(i, 1);

f3=f1~" (DUPLICATED)."~f2.strreverse;

try{
/*write("Enter file name and path: ");
readln(f);
f=strip(f);*/


File inputFile = File(args[1], "r");
File outputFile = File(f3, "w");

enum bufferSize = 8194;
inputFile.byChunk(bufferSize)	// read input in blocks of 8194 
bytes
        .copy(outputFile.lockingBinaryWriter); // copy each block 
into output file


inputFile.close();
outputFile.close();
}


catch(Exception err){
stderr.writefln!"Warning! %s"(err.msg);
return 1;
}



return 0;

}
'''

https://github.com/pascal111-fra/D/blob/main/duplicator2.d


More information about the Digitalmars-d-learn mailing list