Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import std.algorithm;
import std.array;
import std.csv;
import std.stdio;
import std.typecons;
import std.stream;
import std.path;
import std.string;
import std.file;
int main(string[] argv)
{
writeln("phto file mapper");
writeln("---");
const string path = `C:\temp\phto-map.csv`;
const string destRoot = `C:\backup\phto\pathed`;
const string sourceRoot = `C:\backup\phto\media`;
auto header = "id,path,hash,mime_type,type\n";
auto content = header ~ readText(path);
foreach (record; csvReader!(string[string])(content, null)) {
auto sourcePath = buildPath(sourceRoot, record["hash"][0 .. 2], record["hash"][2 .. $]);
auto destPath = buildPath(destRoot, record["path"]).dup.replace("/", dirSeparator);
writeln(record["id"], ": ", record["hash"]);
if (record["type"] != "I") {
writeln("skipping.");
continue;
}
if (exists(sourcePath)) {
auto destDir = dirName(destPath);
if (!exists(destDir)) {
mkdirRecurse(destDir);
}
writeln(sourcePath);
writeln(destDir);
writeln(destPath);
rename(sourcePath, destPath);
}
else {
writeln("already done.");
}
writeln("---");
}
writeln("done.");
readln();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.