Created
July 13, 2014 23:03
-
-
Save brendanmckenzie/4c72e689f232dc72aba6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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