public override bool move(cape.File dest, bool replace) { onError(null); if (!(dest != null)) { onError("null destination"); return(false); } if (dest.exists()) { if (!replace) { onError("target file already exists"); return(false); } if (dest.remove() == false) { onError("Error when removing `" + dest.getPath() + "': " + dest.getLastErrorDescription()); return(false); } } var destf = dest as cape.FileForDotNet; if (!(destf != null)) { return(false); } var v = true; try { System.IO.File.Move(completePath, destf.completePath); } catch (System.Exception e) { onError(e.ToString()); v = false; } return(v); }
public static cape.File forDirectory(cape.File dir, string extension = null) { var tmpdir = dir; if (tmpdir == null) { tmpdir = cape.Environment.getTemporaryDirectory(); } if (tmpdir == null || tmpdir.isDirectory() == false) { return(null); } cape.File v = null; var n = 0; var rnd = new cape.Random(); while (n < 100) { var id = "_tmp_" + cape.String.forInteger((int)cape.SystemClock.asSeconds()) + cape.String.forInteger((int)(rnd.nextInt() % 1000000)); if (object.Equals(extension, null) || cape.String.getLength(extension) < 1) { id = id + extension; } v = tmpdir.entry(id); if (v.exists() == false) { v.touch(); break; } n++; } if (v != null && v.isFile() == false) { v = null; } return(v); }