/// <summary> /// Delete the directory with the given path. /// </summary> public static void Delete(string path, bool recursive) { var file = new JFile(path); if (file.IsDirectory()) { if (recursive) { var children = file.List(); foreach (var child in children) { var childFile = new JFile(child); if (childFile.IsFile()) { childFile.Delete(); } if (childFile.IsDirectory()) { Delete(child, recursive); } } } file.Delete(); } }
/// <summary> /// Gets the file name part (without extension) of the specified path. /// </summary> public static string GetFileNameWithoutExtension(string path) { var name = new JFile(path).GetName(); var index = GetExtensionIndex(name); return((index >= 0) ? name.JavaSubstring(0, index) : name); }
/// <summary> /// Create a unique named zero-byte length temporary file on disk and returns it's path. /// </summary> public static string GetTempFileName() { var rndName = GetRandomFileName(); var index = rndName.IndexOf('.'); return(JFile.CreateTempFile(rndName.JavaSubstring(0, index), rndName.JavaSubstring(index)).GetAbsolutePath()); }
public void testWriteAllText1() { var path = JFile.CreateTempFile("dot42.TestFile-WriteAllText1", "txt"); File.WriteAllText(path.AbsolutePath, "Hello world"); AssertTrue(path.Exists()); path.Delete(); AssertFalse(path.Exists()); }
/// <summary> /// Delete the directory with the given path. /// </summary> public static void Delete(string path) { var file = new JFile(path); if (file.IsDirectory()) { file.Delete(); } }
public void test1() { var path = JFile.CreateTempFile("dot42.TestXLoad-1", "txt"); File.WriteAllText(path, "<root></root>"); var doc = XDocument.Load(path); path.Delete(); AssertNotNull(doc); AssertNotNull(doc.Root); }
public void testWriteAllText2() { const string Data = "Hello worldAllText2"; var path = JFile.CreateTempFile("dot42.TestFile-WriteAllText2", "txt"); File.WriteAllText(path.AbsolutePath, Data); AssertTrue(path.Exists()); var content = File.ReadAllText(path.AbsolutePath); path.Delete(); AssertEquals(content, Data); }
public void test2() { var path = JFile.CreateTempFile("dot42.TestXLoad-2", "txt"); File.WriteAllText(path, "<root></root>"); using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { var doc = XDocument.Load(stream); AssertNotNull(doc); AssertNotNull(doc.Root); } path.Delete(); }
public void test3() { var path = JFile.CreateTempFile("dot42.TestXLoad-3", "txt"); File.WriteAllText(path, "<?xml version=\"1.0\" encoding=\"utf-8\"?><Version xmlns=\"urn:Dot42:TodoApi:1.0\">v1_0</Version>"); using (var stream = new FileStream(path, FileMode.Open, FileAccess.Read)) { var doc = XDocument.Load(stream); AssertNotNull("doc should not be null", doc); AssertNotNull("doc.Root should not be null", doc.Root); AssertTrue("doc.Root.Name.LocalName != 'Version'", doc.Root.Name.LocalName == "Version"); AssertTrue("doc.Root.Value != 'v1_0' but:" + doc.Root.Value, doc.Root.Value == "v1_0"); } path.Delete(); }
public void testWriteAllBytes1() { var data = new byte[] { 1, 2, 3, 4 }; var path = JFile.CreateTempFile("dot42.TestFile-WriteAllBytes1", "txt"); File.WriteAllBytes(path.AbsolutePath, data); AssertTrue(path.Exists()); var readData = File.ReadAllBytes(path.AbsolutePath); path.Delete(); AssertFalse(path.Exists()); AssertEquals(data.Length, readData.Length); for (var i = 0; i < data.Length; i++) { AssertEquals(data[i], readData[i]); } }
/// <summary> /// Delete the directory with the given path. /// </summary> public static void Delete(string path, bool recursive) { var file = new JFile(path); if (file.IsDirectory()) { if (recursive) { var children = file.List(); foreach (var child in children) { var childFile = new JFile(child); if (childFile.IsFile()) childFile.Delete(); if (childFile.IsDirectory()) Delete(child, recursive); } } file.Delete(); } }
private Java.Io.File[] GetEntries(string path) { var dir = new Java.Io.File(path); if (dir.Exists() && dir.IsDirectory()) { var entries = dir.ListFiles(); if (entries != null) { var list = entries.OrderBy(x => x.Name).ToList(); if (path != startPath) { var parent = dir.ParentFile; if (parent != null) { list.Insert(0, parent); } } return list.ToArray(); } } return new Java.Io.File[0]; }
private Java.Io.File[] GetEntries(string path) { var dir = new Java.Io.File(path); if (dir.Exists() && dir.IsDirectory()) { var entries = dir.ListFiles(); if (entries != null) { var list = entries.OrderBy(x => x.Name).ToList(); if (path != startPath) { var parent = dir.ParentFile; if (parent != null) { list.Insert(0, parent); } } return(list.ToArray()); } } return(new Java.Io.File[0]); }
/// <summary> /// Initialize activity /// </summary> protected override void OnCreate(Bundle savedInstance) { base.OnCreate(savedInstance); try { var httpCacheDir = new Java.Io.File(GetCacheDir(), "http"); const long httpCacheSize = 10 * 1024 * 1024; // 10 MB HttpResponseCache.Install(httpCacheDir, httpCacheSize); } catch (IOException ex) { Log.E(Tag, "HTTP response cache installation failed. " + ex.Message + " " + ex.StackTrace); } SetContentView(R.Layouts.MainLayout); _fixtureList = FindViewById <ListView>(R.Ids.fixtureList); _fixturesArray = _fixtures.ToArray(); _adapter = new ArrayAdapter <Fixture>(this, Android.R.Layout.Simple_list_item_1, _fixturesArray); _fixtureList.SetAdapter(_adapter); GetFixturesAsync(); }
/// <summary> /// Gets the file name part (without extension) of the specified path. /// </summary> public static string GetFileNameWithoutExtension(string path) { var name = new JFile(path).GetName(); var index = GetExtensionIndex(name); return (index >= 0) ? name.JavaSubstring(0, index) : name; }
/// <summary> /// Delete the directory with the given path. /// </summary> public static void Delete(string path) { var file = new JFile(path); if (file.IsDirectory()) file.Delete(); }
/// <summary> /// Initialize activity /// </summary> protected override void OnCreate(Bundle savedInstance) { base.OnCreate(savedInstance); try { var httpCacheDir = new Java.Io.File(GetCacheDir(), "http"); const long httpCacheSize = 10 * 1024 * 1024; // 10 MB HttpResponseCache.Install(httpCacheDir, httpCacheSize); } catch (IOException ex) { Log.E(Tag, "HTTP response cache installation failed. " + ex.Message + " " + ex.StackTrace); } SetContentView(R.Layouts.MainLayout); _fixtureList = FindViewById<ListView>(R.Ids.fixtureList); _fixturesArray = _fixtures.ToArray(); _adapter = new ArrayAdapter<Fixture>(this, Android.R.Layout.Simple_list_item_1, _fixturesArray); _fixtureList.SetAdapter(_adapter); GetFixturesAsync(); }
public static /*DirectoryInfo*/ void CreateDirectory(string path) { var file = new JFile(path); var isCreated = file.Mkdirs(); }
/// <summary> /// Does a directory with given path exist on the filesystem? /// </summary> public static bool Exists(string path) { var file = new JFile(path); return(file.IsDirectory() && file.Exists()); }
/// <summary> /// Does a directory with given path exist on the filesystem? /// </summary> public static bool Exists(string path) { var file = new JFile(path); return file.IsDirectory() && file.Exists(); }