Skip to content

Instantly share code, notes, and snippets.

@brendanmckenzie
Created July 13, 2014 23:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brendanmckenzie/4c72e689f232dc72aba6 to your computer and use it in GitHub Desktop.
Save brendanmckenzie/4c72e689f232dc72aba6 to your computer and use it in GitHub Desktop.
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