Concatenating files
Let's suppose that we have a number of text files we want to glue together in one big file. This recipe with code in the project concat_files
shows you how this can be done.
How to do it...
The program is launched from the command line in the bin
folder (or in Dart Editor with a Managed Launch with Script
arguments file1.txt
file2.txt file.txt
) as dart co
ncat.dart
file1.txt file2.txt file.txt
, where file1.txt
and file2.txt
are the files to be concatenated (there can be two or more files) into file.txt
. The following is the code to perform this:
import 'dart:io'; import 'package:args/args.dart'; ArgResults argResults; File output; void main(List<String> arguments) { final parser = new ArgParser(); argResults = parser.parse(arguments); final outFile = argResults.rest.last; List<String> files = argResults.rest.sublist(0, argResults.rest.length - 1); if (files.isEmpty) { print('No files provided to concatenate!'); exit(1); } output = new...