I have been writing a program to backup files (attached).
I've tried to add a new option that restores the last backup of all the files in a directory:
static void RestoreDirBackup(string filename) {
string file = Path.GetFullPath(filename);
string[] backups = Directory.GetFiles(BackupLocation + file);
if(!Directory.Exists(file)){
Directory.CreateDirectory(file);
}
string lastfile = backups[0];
string newestfile = backups[0];
long newestdate = long.Parse(Path.GetExtension(backups[0]));
List<string> lastrev = new List<string>();
for(int y=0; y<backups.Length; y++){
string f = backups[y];
if(f == lastfile){
long thisdate = long.Parse(Path.GetExtension(f));
if(thisdate > newestdate){
newestdate = thisdate;
newestfile = f;
}
}else{
lastrev.Add(newestfile);
newestdate = long.Parse(Path.GetExtension(f));
newestfile = f;
}
}
foreach(string f in lastrev){
File.Copy(f, file+Path.GetFileName(f), true);
}
}
When I try to run it it gives this error:
[matio@myhost Debug]$ mono Chronojohn.exe dir ~/test2
Unhandled Exception: System.FormatException: Input string was not in the correct format
at System.Int64.Parse (System.String s) [0x00000] in <filename unknown>:0
at Chronojohn.MainClass.RestoreDirBackup (System.String filename) [0x00000] in <filename unknown>:0
at Chronojohn.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0
What's wrong with the input of long.Parse?