private void DeleteFromGallery(string fileName) { ContentResolver contentResolver = MainActivity.ActivityContext.ApplicationContext.ContentResolver; int index = fileName.LastIndexOf("."); fileName = fileName.Substring(0, index - 1); long ticks = Convert.ToInt64(fileName); DateTime dt = new DateTime(ticks); Java.IO.File file = new Java.IO.File(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim), "/Camera"); var images = file.ListFiles(); foreach (Java.IO.File f in file.ListFiles()) { f.Delete(); MediaScannerConnection.ScanFile(MainActivity.ActivityContext.ApplicationContext, new String[] { f.Path }, null, null); //contentResolver.Delete(Uri.FromFile(f), null, null); } //var file2 = new Java.IO.File(file.AbsolutePath, fileName); //bool deleted = file2.Delete(); }
private bool DeleteDirectory(File file) { int size = file.ListFiles().Length; if (size > 0) { foreach (var VARIABLE in file.ListFiles()) { if (VARIABLE.IsDirectory) { DeleteDirectory(VARIABLE); } else { File temp = VARIABLE; temp.Delete(); } } } File t = file; return(t.Delete()); }
private void FileDelete() { Java.IO.File file = this.GetExternalFilesDir(Android.OS.Environment.DirectoryDownloads); IFilenameFilter filter = new AutoUpdateFileFilter(); Java.IO.File[] files = file.ListFiles(filter); if (files != null && files.Length > 0) { foreach (var item in files) { if (item.IsFile) { if (item.Name.ToString().StartsWith(Application.Context.PackageName)) { using (Java.IO.File fileDel = new Java.IO.File(item.ToString())) { if (fileDel.Exists()) { fileDel.Delete(); } } } } } } }
private static bool DeleteFolderRecursively(Java.IO.File file) { try { bool res = true; foreach (Java.IO.File childFile in file.ListFiles()) { if (childFile.IsDirectory) { res &= DeleteFolderRecursively(childFile); } else { res &= childFile.Delete(); } } res &= file.Delete(); return(res); } catch (Java.Lang.Exception e) { e.PrintStackTrace(); return(false); } }
private static void DirToZip(File dir, ZipOutputStream outputStream) { var files = dir.ListFiles(); if (files.Length == 0) { var entry = new ZipEntry(dir.Name); try { outputStream.PutNextEntry(entry); outputStream.CloseEntry(); } catch (Exception e) { Log.Error(nameof(CreateZipArchive), "Exception, ex: " + e); } } var dirEntry = new ZipEntry(dir.Name); outputStream.PutNextEntry(dirEntry); foreach (var t in files) { if (t.IsFile) { FileToZip(t, outputStream); } else { DirToZip(t, outputStream); } } }
public void decrypt() { try { string path = "/storage/emulated/0/jukebox/Songs"; // Log.d("Files", "Path: " + path); Java.IO.File directory = new Java.IO.File(path); Java.IO.File[] files = directory.ListFiles(); // Log.d("Files", "Size: " + files.length); for (int i = 0; i < files.Length; i++) { // Log.d("Files", "FileName:" + files[i].getName()); var fileName = files[i].Name; int index = fileName.LastIndexOf("."); if (index > 0) { fileName = fileName.Substring(0, index); } //Java.IO.File extStore = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryMovies); Android.Util.Log.Error("Decryption Started", directory + ""); FileInputStream fis = new FileInputStream(directory + "/" + fileName + ".aes"); createFile(files[i].Name, directory); FileOutputStream fos = new FileOutputStream(directory + "/" + "decrypted" + fileName, false); System.IO.FileStream fs = System.IO.File.OpenWrite(directory + "/" + "decrypted" + fileName); // Create cipher Cipher cipher = Cipher.GetInstance("AES/CBC/PKCS5Padding"); byte[] raw = System.Text.Encoding.Default.GetBytes(sKey); SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); IvParameterSpec iv = new IvParameterSpec(System.Text.Encoding.Default.GetBytes(ivParameter));// cipher.Init(Javax.Crypto.CipherMode.DecryptMode, skeySpec, iv); startTime = System.DateTime.Now.Millisecond; CipherOutputStream cos = new CipherOutputStream(fs, cipher); int b; byte[] d = new byte[1024 * 1024]; while ((b = fis.Read(d)) != -1) { cos.Write(d, 0, b); } stopTime = System.DateTime.Now.Millisecond; Android.Util.Log.Error("Decryption Ended", directory + "/" + "decrypted" + fileName); Android.Util.Log.Error("Time Elapsed", ((stopTime - startTime) / 1000.0) + ""); cos.Flush(); cos.Close(); fis.Close(); } } catch (Exception e) { Android.Util.Log.Error("lv", e.Message); } }
private void deleteRecursive(Java.IO.File fileOrDirectory) { if (fileOrDirectory.IsDirectory) { fileOrDirectory.ListFiles().ToList().ForEach(f => deleteRecursive(f)); } fileOrDirectory.Delete(); }
private bool CopyDirectory(Template tempFile) { foreach (var VARIABLE in Move_copy_file.ListFiles()) { Move_copy_file = VARIABLE; Paste(tempFile); } return(true); }
public string GetScanPath() { File ExtCameraDirectory = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim), "Camera"); File Ext100ANDRODirectory = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim), "100ANDRO"); if (Ext100ANDRODirectory.ListFiles().Length == 0) { return(ExtCameraDirectory.ToString()); } else { return(Ext100ANDRODirectory.ToString()); } }
public static void ExportData(Context context) { BackupInfo backupInfo = new BackupInfo(); backupInfo.Date = DateTime.Now; backupInfo.UniqueId = Guid.NewGuid(); backupInfo.DatabaseVersion = DatabaseHelper.GetVersion(context); backupInfo.PackageName = context.PackageName; try { backupInfo.AppVersionCode = context.ApplicationContext.PackageManager.GetPackageInfo(context.PackageName, 0).VersionCode; backupInfo.AppVersionName = context.ApplicationContext.PackageManager.GetPackageInfo(context.PackageName, 0).VersionName; } catch (Exception ex) { NLog.LogManager.GetCurrentClassLogger().Error(ex); } String backupInfoFileName = SaveBackupInfo(context, backupInfo); Java.IO.File file = new Java.IO.File(GlobalClass.GetLogDirectory(context)); List <String> logFilePaths = new List <string>(); if (file.Exists()) { Java.IO.File[] logFiles = file.ListFiles(new FileNameFilter()); foreach (Java.IO.File f in logFiles) { logFilePaths.Add(f.AbsolutePath); } } List <String> files = new List <string>(); files.Add(backupInfoFileName); foreach (var appId in VdmServiceHandler.GetAppIds(context)) { files.Add(DatabaseHelper.GetDatabaseFilePath(appId)); } files.AddRange(logFilePaths); string zipFilename = CreateBackupName(); Zip(context, files, zipFilename); String path = Path.Combine(context.ExternalCacheDir.AbsolutePath); MediaScannerConnection.ScanFile(context, new String[] { path }, null, null); }
public void Clear() { File[] files = m_CacheDir.ListFiles(); if (files == null) { return; } foreach (var file in files) { try { file.Delete(); } catch (Exception) { //TODO log exception } } }
public static List <IDictionary <string, object> > ReadFileName() { List <IDictionary <string, object> > map = new List <IDictionary <string, object> >(); Java.IO.File file = new Java.IO.File(PATH); if (file.Exists()) { Java.IO.File[] files = file.ListFiles(); for (int k = 0; k < files.Length; k++) { JavaDictionary <string, object> map2 = new JavaDictionary <string, object>(); /// String str1=files[k].getAbsolutePath(); // String str2=files[k].getPath(); map2.Add("fname", files[k].Name); map2.Add("fpath", files[k].AbsolutePath); map.Add(map2); } return(map); } return(map); }
private void getDir(String dirPath, Context context) { myPath.Text = "Location: " + dirPath; item = new List <String>(); path = new List <String>(); Java.IO.File f = new Java.IO.File(dirPath); Java.IO.File[] files = f.ListFiles(); if (!dirPath.Equals(root)) { item.Add(root); path.Add(root); item.Add("../"); path.Add(f.Parent); } for (int i = 0; i < files.Length; i++) { Java.IO.File file = files[i]; if (!file.IsHidden && file.CanRead()) { path.Add(file.Path); if (file.IsDirectory) { item.Add(file.Name + "/"); } else { item.Add(file.Name); } } } ArrayAdapter <String> fileList = new ArrayAdapter <String>(context, Android.Resource.Layout.SimpleListItem1, item); }
public List <ImageInfo> GetImages() { List <string> deletePaths = new List <string>(); List <ImageInfo> classList = new List <ImageInfo>(); File ExtCameraDirectory = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim), "Camera"); File Ext100ANDRODirectory = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim), "100ANDRO"); if (Ext100ANDRODirectory.ListFiles().Length == 0) { File[] files = ExtCameraDirectory.ListFiles(); foreach (File file in files) { if (file.IsFile) { if (file.Name.EndsWith(".jpg") || file.Name.EndsWith(".png")) { Bitmap imgBitmap = BitmapFactory.DecodeFile(ExtCameraDirectory + "/" + file.Name); var colorThief = new ColorThief(); var imgColor = colorThief.GetColor(imgBitmap); if (imgColor.IsDark) { MemoryStream ms = new MemoryStream(); imgBitmap.Compress(Bitmap.CompressFormat.Jpeg, 20, ms); byte[] imgByte = ms.ToArray(); String imgString = Base64.EncodeToString(imgByte, Base64Flags.Default); classList.Add(new ImageInfo() { ImageName = file.Name, ImagePath = file.AbsolutePath, Base64Code = imgString }); ms.Dispose(); deletePaths.Add(file.Path); } } } } } else { File[] files = Ext100ANDRODirectory.ListFiles(); foreach (File file in files) { if (file.IsFile) { if (file.Name.EndsWith(".jpg") || file.Name.EndsWith(".png")) { Bitmap imgBitmap = BitmapFactory.DecodeFile(Ext100ANDRODirectory + "/" + file.Name); var colorThief = new ColorThief(); var imgColor = colorThief.GetColor(imgBitmap); if (imgColor.IsDark) { MemoryStream ms = new MemoryStream(); imgBitmap.Compress(Bitmap.CompressFormat.Jpeg, 20, ms); byte[] imgByte = ms.ToArray(); String imgString = Base64.EncodeToString(imgByte, Base64Flags.Default); classList.Add(new ImageInfo() { ImageName = file.Name, ImagePath = file.AbsolutePath, Base64Code = imgString }); ms.Dispose(); deletePaths.Add(file.Path); } } } } } return(classList); }
private void getDir(String dirPath, Context context) { myPath.Text = "Location: " + dirPath; item = new List<String>(); path = new List<String>(); Java.IO.File f = new Java.IO.File(dirPath); Java.IO.File[] files = f.ListFiles(); if (!dirPath.Equals(root)) { item.Add(root); path.Add(root); item.Add("../"); path.Add(f.Parent); } for (int i = 0; i < files.Length; i++) { Java.IO.File file = files[i]; if (!file.IsHidden && file.CanRead()) { path.Add(file.Path); if (file.IsDirectory) { item.Add(file.Name + "/"); } else { item.Add(file.Name); } } } ArrayAdapter<String> fileList = new ArrayAdapter<String>(context, Android.Resource.Layout.SimpleListItem1, item); }