async void GetTreeForFolder(ExternalStorageFolder folder) { CurrentItems.Clear(); var folderList = await folder.GetFoldersAsync(); foreach (ExternalStorageFolder _folder in folderList) { CurrentItems.Add(new FileExplorerItem() { IsFolder = true, Name = _folder.Name, Path = _folder.Path }); } foreach (ExternalStorageFile _file in await folder.GetFilesAsync()) { CurrentItems.Add(new FileExplorerItem() { IsFolder = false, Name = _file.Name, Path = _file.Path }); } if (!_folderTree.Contains(folder)) { _folderTree.Push(folder); } CurrentPath = _folderTree.First().Path; }
private async void loadFolder(ExternalStorageFolder fol_tmp) { try { current_folder = fol_tmp; folders.Clear(); files.Clear(); IEnumerable<ExternalStorageFile> files_tmp = await fol_tmp.GetFilesAsync(); IEnumerable<ExternalStorageFolder> folders_tmp = await fol_tmp.GetFoldersAsync(); foreach (ExternalStorageFile i in files_tmp) { files.Add(i); } foreach (ExternalStorageFolder i in folders_tmp) { folders.Add(i); } } catch (Exception w) { MessageBox.Show(w.Message + "\n\n#1"); } // Tu sie cos kiedys napisze }
/// <summary> /// Gets all external storage files /// </summary> /// <param name="sdCard"></param> /// <returns></returns> public async Task <ObservableCollection <ExternalStorageFile> > GetExternal_GPXFiles(string folder, string fileExtension) { ObservableCollection <ExternalStorageFile> storageFIle = new ObservableCollection <ExternalStorageFile>(); try { ExternalStorageDevice sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault(); if (sdCard != null) { ExternalStorageFolder routesFolder = await sdCard.GetFolderAsync(folder); IEnumerable <ExternalStorageFile> routeFiles = await routesFolder.GetFilesAsync(); foreach (ExternalStorageFile extStoreFile in routeFiles) { if (extStoreFile.Path.EndsWith(fileExtension)) { storageFIle.Add(extStoreFile); } } } else { MessageBox.Show("SD card not found, Please make sure the SD card is inserted properly."); } } catch (FileNotFoundException) { MessageBox.Show("The file folder " + folder + " not found."); return(null); } return(storageFIle); }
public async Task GetFilesAsync(ExternalStorageFolder folder, List<ExternalStorageFile> files) { var subFolders = await folder.GetFoldersAsync(); foreach (var subFolder in subFolders) { await GetFilesAsync(subFolder, files); } files.AddRange(await folder.GetFilesAsync()); }
public async Task GetFilesAsync(ExternalStorageFolder folder, List <ExternalStorageFile> files) { var subFolders = await folder.GetFoldersAsync(); foreach (var subFolder in subFolders) { await GetFilesAsync(subFolder, files); } files.AddRange(await folder.GetFilesAsync()); }
public static async void ExportDb() { try { StorageFile file = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("weibodb.sqlite"); ExternalStorageDevice device = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault(); ExternalStorageFolder folder = await device.GetFolderAsync("WeiBo"); //await file.CopyAsync(folder); } catch { } }
private async void RefreshList() { // Clear the collection bound to the page. Files.Clear(); // Connect to the current SD card. ExternalStorageDevice _sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault(); // If the SD card is present, add KDBX files to the Files collection. if (_sdCard != null) { try { // Look for a folder on the SD card named Files. ExternalStorageFolder dbFolder = await _sdCard.GetFolderAsync("CodeSafe"); // Get all files from the CodeSafe folder. IEnumerable <ExternalStorageFile> routeFiles = await dbFolder.GetFilesAsync(); // Add each KDBX file to the Files collection. foreach (ExternalStorageFile esf in routeFiles) { if (esf.Path.EndsWith(".kdbx")) { Files.Add(esf); } } } catch (FileNotFoundException) { // No CodeSafe folder is present. MessageBox.Show("The CodeSafe folder is missing on your SD card. Add a CodeSafe folder containing at least one .kdbx file and try again."); } } else { // No SD card is present. MessageBox.Show("The SD card is mssing. Insert an SD card that has a CodeSafe folder containing at least one .kdbx file and try again."); } }
/// <summary> /// Checks to see if a folder exists on the sd card. /// </summary> /// <param name="folderName"></param> /// <returns></returns> public async Task <bool> SDCard_CheckFolder(string folderName) { try { if (folderName != string.Empty) { ExternalStorageDevice sdcard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault(); if (sdcard != null) { ExternalStorageFolder folder = await sdcard.GetFolderAsync(folderName); return(true); } return(false); } return(false); } catch (FileNotFoundException) { return(false); } }
void ExplorerControl_OnDismiss(Control.Interop.StorageTarget target, object file) { if (file != null) { switch (target) { case Control.Interop.StorageTarget.ExternalStorage: { if (ExplorerControl.SelectionMode == SelectionMode.File) { ExternalStorageFile _stFile = (ExternalStorageFile)file; Debug.WriteLine(_stFile.Path); } else if (ExplorerControl.SelectionMode == SelectionMode.Folder) { ExternalStorageFolder folder = (ExternalStorageFolder)file; Debug.WriteLine(folder.Path); } else { List <FileExplorerItem> items = (List <FileExplorerItem>)file; foreach (var item in items) { Debug.WriteLine(item.Path); } } break; } case Control.Interop.StorageTarget.IsolatedStorage: { StorageFile _stFile = (StorageFile)file; Debug.WriteLine(_stFile.Path); break; } } } }
private async System.Threading.Tasks.Task ShowList() { ExternalStorageDevice device = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault(); ExternalStorageFolder folder = await device.RootFolder.GetFolderAsync("ADV"); ExternalStorageFolder[] gamefolders = (await folder.GetFoldersAsync()).ToArray <ExternalStorageFolder>(); foreach (ExternalStorageFolder f in gamefolders) { ExternalStorageFile[] files = (await f.GetFilesAsync()).ToArray <ExternalStorageFile>(); int count = 0; foreach (ExternalStorageFile ef in files) { if (ef.Name == "nscript.dat" || ef.Name == "nscript.___" || ef.Name == "nscr.dat") { count++; } } if (count >= 1) { List.Text += f.Name + '\n'; } } }
GetFoldersAndFilesAsync(string path, StorageType storageType) { bool status = true; List <Dictionary <string, object> > fileList = new List <Dictionary <string, object> >(); string error = String.Empty; try { if (storageType == StorageType.External) { ExternalStorageDevice sdCard = await FileManager.GetExternalStorageAsync(); if (sdCard != null) { ExternalStorageFolder root = await sdCard.GetFolderAsync(path); IEnumerable <ExternalStorageFolder> folders = await root.GetFoldersAsync(); // Get the directories list folders.ToList().ForEach(dir => { Dictionary <string, object> fileInfo = new Dictionary <string, object>(); fileInfo.Add("name", dir.Path); fileInfo.Add("type", FileType.Directory); fileList.Add(fileInfo); }); // Get the files list IEnumerable <ExternalStorageFile> files = await root.GetFilesAsync(); files.ToList().ForEach(file => { Dictionary <string, object> fileInfo = new Dictionary <string, object>(); fileInfo.Add("name", file.Path); fileInfo.Add("type", FileType.File); fileList.Add(fileInfo); }); } else { status = false; error = Constants.STRING_EXTERNAL_STORAGE_ERROR; } } else if (FileManager.DirectoryExists(path)) { using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication()) { // Get the directories list string[] files = storage.GetDirectoryNames(path + "\\*"); foreach (string file in files) { Dictionary <string, object> fileInfo = new Dictionary <string, object>(); fileInfo.Add("name", file); fileInfo.Add("type", FileType.Directory); fileList.Add(fileInfo); } // Get the files list files = storage.GetFileNames(path + "\\*"); foreach (string file in files) { Dictionary <string, object> fileInfo = new Dictionary <string, object>(); fileInfo.Add("name", file); fileInfo.Add("type", FileType.File); fileList.Add(fileInfo); } } } } catch (Exception e) { status = false; error = e.Message; Logger.Error("Error retrieving file list as JSON. Reason - " + error); } return(Tuple.Create(status, fileList, error)); }
public static async void Update(DatabaseInfo info, Func <DatabaseInfo, bool> queryUpdate, ReportUpdateResult report) { if (info == null) { throw new ArgumentNullException("info"); } if (queryUpdate == null) { throw new ArgumentNullException("queryUpdate"); } if (report == null) { throw new ArgumentNullException("report"); } // Connect to the current SD card. ExternalStorageDevice _sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault(); // If the SD card is present, add KDBX files to the Files collection. if (_sdCard != null) { try { // Look for a folder on the SD card named Files. ExternalStorageFolder dbFolder = await _sdCard.GetFolderAsync("CodeSafe"); // Get all files from the CodeSafe folder. IEnumerable <ExternalStorageFile> routeFiles = await dbFolder.GetFilesAsync(); bool found = false; foreach (ExternalStorageFile esf in routeFiles) { if (esf.Name.RemoveKdbx() == info.Details.Name) { found = true; Stream stream = await esf.OpenForReadAsync(); var check = DatabaseVerifier .VerifyUnattened(stream); if (check.Result == VerifyResultTypes.Error) { report(info, SyncResults.Failed, check.Message); return; } info.SetDatabase(stream, info.Details); report(info, SyncResults.Downloaded, null); break; } } if (!found) { MessageBox.Show("The original database file is not found in CodeSafe folder on your SD card anymore. Did you delete it?"); } } catch (FileNotFoundException) { // No CodeSafe folder is present. MessageBox.Show("The CodeSafe folder is missing on your SD card. Add a CodeSafe folder containing at least one .kdbx file and try again."); } } else { // No SD card is present. MessageBox.Show("The SD card is mssing. Insert an SD card that has a CodeSafe folder containing at least one .kdbx file and try again."); } }
async void OpenFolder(ExternalStorageFolder folderToOpen) { try { //new list List <SDCardListItem> listItems = new List <SDCardListItem>(); // Get all folders on root List <ExternalStorageFolder> listFolders = (await folderToOpen.GetFoldersAsync()).ToList(); foreach (ExternalStorageFolder folder in listFolders) { SDCardListItem item = new SDCardListItem() { isFolder = true, Name = folder.Name, ParentPath = folderToOpen.Path, ThisFolder = folder }; listItems.Add(item); } List <ExternalStorageFile> listFiles = (await folderToOpen.GetFilesAsync()).ToList(); foreach (ExternalStorageFile file in listFiles) { SDCardListItem item = new SDCardListItem() { isFolder = false, Name = file.Name, ParentPath = folderToOpen.Path, ThisFile = file }; if (item.ThisFile.Path.ToLower().EndsWith(".gb") || item.ThisFile.Path.ToLower().EndsWith(".gbc") || item.ThisFile.Path.ToLower().EndsWith(".gba")) { item.Type = SkyDriveItemType.ROM; } else if (item.ThisFile.Path.ToLower().EndsWith(".sav")) { item.Type = SkyDriveItemType.SRAM; } else if (item.ThisFile.Path.ToLower().EndsWith(".sgm")) { item.Type = SkyDriveItemType.Savestate; } else if (item.ThisFile.Path.ToLower().EndsWith(".zib") || item.ThisFile.Path.ToLower().EndsWith(".zip")) { item.Type = SkyDriveItemType.Zip; } else if (item.ThisFile.Path.ToLower().EndsWith(".rar")) { item.Type = SkyDriveItemType.Rar; } else if (item.ThisFile.Path.ToLower().EndsWith(".7z")) { item.Type = SkyDriveItemType.SevenZip; } else { item.Type = SkyDriveItemType.File; } listItems.Add(item); } //ordered by name listItems = listItems.OrderBy(x => x.Name).ToList(); this.skydriveStack.Add(listItems); this.skydriveList.ItemsSource = listItems; } catch (Exception) { MessageBox.Show(AppResources.ErrorReadingSDCardText); } }
async void GetTreeForFolder(ExternalStorageFolder folder) { CurrentItems.Clear(); var folderList = await folder.GetFoldersAsync(); foreach (ExternalStorageFolder _folder in folderList) { CurrentItems.Add(new FileExplorerItem() { IsFolder = true, Name = _folder.Name, Path = _folder.Path }); } foreach (ExternalStorageFile _file in await folder.GetFilesAsync()) { CurrentItems.Add(new FileExplorerItem() { IsFolder = false, Name = _file.Name, Path = _file.Path }); } if (!_folderTree.Contains(folder)) _folderTree.Push(folder); CurrentPath = _folderTree.First().Path; }
async void GetTreeForExternalFolder(ExternalStorageFolder folder) { if (!_externalFolderTree.Contains(folder)) _externalFolderTree.Push(folder); ProcessSelectedItems(); CurrentItems.Clear(); var folderList = await folder.GetFoldersAsync(); foreach (ExternalStorageFolder _folder in folderList) { FileExplorerItem item = (from c in _selectedItems where c.Path == _folder.Path select c).FirstOrDefault(); FileExplorerItem _addItem = new FileExplorerItem() { IsFolder = true, Name = _folder.Name, Path = _folder.Path, Selected = item != null ? true : false }; CurrentItems.Add(_addItem); } var fileList = await folder.GetFilesAsync(); if (fileList != null) { foreach (ExternalStorageFile _file in fileList) { FileExplorerItem item = GetItemFromPath(_file.Path); if (((ExtensionRestrictions & (Interop.ExtensionRestrictions.Custom | Interop.ExtensionRestrictions.InheritManifest)) != 0) && (Extensions.Count != 0)) { string extension = Path.GetExtension(_file.Name); if (Extensions.FindIndex(x => x.Equals(extension, StringComparison.OrdinalIgnoreCase)) != -1) { CurrentItems.Add(new FileExplorerItem() { IsFolder = false, Name = _file.Name, Path = _file.Path, Selected = item != null ? true : false }); } } else { CurrentItems.Add(new FileExplorerItem() { IsFolder = false, Name = _file.Name, Path = _file.Path, Selected = item != null ? true : false }); } } } CurrentPath = _externalFolderTree.First().Path; }
private async void buildFileList() { // enables progress indicator //ProgressIndicator indicator = SystemTray.ProgressIndicator; //if (indicator != null) //{ // //indicator.Text = "载入文件中 ..."; // //indicator.IsVisible = true; //} this.files = new List <Book>(); Book sampleBook = new Book(); sampleBook.Name = "《三国演义》节选"; sampleBook.Path = "试阅文本"; sampleBook.IsSample = true; this.files.Add(sampleBook); // sandbox try { // sandbox root folder IStorageFolder routesFolder = ApplicationData.Current.LocalFolder; // Get all files from the Routes folder. IEnumerable <StorageFile> files = await routesFolder.GetFilesAsync(); Debug.WriteLine("found folder"); // Add each GPX file to the Routes collection. foreach (StorageFile esf in files) { Debug.WriteLine("found file " + esf.Name); if (esf.Path.EndsWith(".txtx")) { int loc = esf.Name.LastIndexOf(".txtx"); string bookname = esf.Name.Substring(0, loc); // remove first part of book names loc = bookname.LastIndexOf("-"); if (loc + 1 < bookname.Length) { bookname = bookname.Substring(loc + 1).Trim(); } // add to file list Book newBook = new Book(); newBook.Name = bookname; newBook.Path = "\\" + esf.Path.Split(new String[] { "\\" }, StringSplitOptions.RemoveEmptyEntries).Last(); this.files.Add(newBook); } } Debug.WriteLine("done"); } catch (FileNotFoundException) { // No Routes folder is present. Debug.WriteLine("Folder not found."); } // Connect to the current SD card. ExternalStorageDevice _sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault(); // If the SD card is present, add GPX files to the Routes collection. if (_sdCard != null) { // root folder try { // Look for a folder on the SD card ExternalStorageFolder folder = _sdCard.RootFolder; // Get all files from the Routes folder. IEnumerable <ExternalStorageFile> files = await folder.GetFilesAsync(); Debug.WriteLine("found folder"); // Add each GPX file to the Routes collection. foreach (ExternalStorageFile esf in files) { Debug.WriteLine("found file " + esf.Name); if (esf.Path.EndsWith(".txtx")) { int loc = esf.Name.LastIndexOf(".txtx"); string bookname = esf.Name.Substring(0, loc); // remove first part of book names loc = bookname.LastIndexOf("-"); if (loc + 1 < bookname.Length) { bookname = bookname.Substring(loc + 1).Trim(); } // add to file list Book newBook = new Book(); newBook.Name = bookname; newBook.Path = esf.Path; this.files.Add(newBook); } } Debug.WriteLine("done"); } catch (FileNotFoundException) { // No Routes folder is present. Debug.WriteLine("Folder not found."); } // Book try { // Look for a folder on the SD card named Routes. ExternalStorageFolder folder = await _sdCard.GetFolderAsync("Book"); // Get all files from the Routes folder. IEnumerable <ExternalStorageFile> files = await folder.GetFilesAsync(); Debug.WriteLine("found folder"); // Add each GPX file to the Routes collection. foreach (ExternalStorageFile esf in files) { Debug.WriteLine("found file " + esf.Name); if (esf.Path.EndsWith(".txtx")) { int loc = esf.Name.LastIndexOf(".txtx"); string bookname = esf.Name.Substring(0, loc); // remove first part of book names loc = bookname.LastIndexOf("-"); if (loc + 1 < bookname.Length) { bookname = bookname.Substring(loc + 1).Trim(); } // add to file list Book newBook = new Book(); newBook.Name = bookname; newBook.Path = esf.Path; this.files.Add(newBook); } } Debug.WriteLine("done"); } catch (FileNotFoundException) { // No Routes folder is present. Debug.WriteLine("Folder not found."); } // Books try { // Look for a folder on the SD card named Routes. ExternalStorageFolder folder = await _sdCard.GetFolderAsync("Books"); // Get all files from the Routes folder. IEnumerable <ExternalStorageFile> files = await folder.GetFilesAsync(); Debug.WriteLine("found folder"); // Add each GPX file to the Routes collection. foreach (ExternalStorageFile esf in files) { Debug.WriteLine("found file " + esf.Name); if (esf.Path.EndsWith(".txtx")) { int loc = esf.Name.LastIndexOf(".txtx"); string bookname = esf.Name.Substring(0, loc); // remove first part of book names loc = bookname.LastIndexOf("-"); if (loc + 1 < bookname.Length) { bookname = bookname.Substring(loc + 1).Trim(); } // add to file list Book newBook = new Book(); newBook.Name = bookname; newBook.Path = esf.Path; this.files.Add(newBook); } } Debug.WriteLine("done"); } catch (FileNotFoundException) { // No Routes folder is present. Debug.WriteLine("Folder not found."); } } else { // No SD card is present. Debug.WriteLine("The SD card is mssing."); } this.fileList.ItemsSource = this.files; }
async void GetTreeForExternalFolder(ExternalStorageFolder folder) { if (!_externalFolderTree.Contains(folder)) { _externalFolderTree.Push(folder); } ProcessSelectedItems(); CurrentItems.Clear(); var folderList = await folder.GetFoldersAsync(); foreach (ExternalStorageFolder _folder in folderList) { FileExplorerItem item = (from c in _selectedItems where c.Path == _folder.Path select c).FirstOrDefault(); FileExplorerItem _addItem = new FileExplorerItem() { IsFolder = true, Name = _folder.Name, Path = _folder.Path, Selected = item != null ? true : false }; CurrentItems.Add(_addItem); } var fileList = await folder.GetFilesAsync(); if (fileList != null) { foreach (ExternalStorageFile _file in fileList) { FileExplorerItem item = GetItemFromPath(_file.Path); if (((ExtensionRestrictions & (Interop.ExtensionRestrictions.Custom | Interop.ExtensionRestrictions.InheritManifest)) != 0) && (Extensions.Count != 0)) { string extension = Path.GetExtension(_file.Name); if (Extensions.FindIndex(x => x.Equals(extension, StringComparison.OrdinalIgnoreCase)) != -1) { CurrentItems.Add(new FileExplorerItem() { IsFolder = false, Name = _file.Name, Path = _file.Path, Selected = item != null ? true : false }); } } else { CurrentItems.Add(new FileExplorerItem() { IsFolder = false, Name = _file.Name, Path = _file.Path, Selected = item != null ? true : false }); } } } CurrentPath = _externalFolderTree.First().Path; }