本文整理汇总了C#中Windows.Storage.StorageFolder.GetFoldersAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFolder.GetFoldersAsync方法的具体用法?C# StorageFolder.GetFoldersAsync怎么用?C# StorageFolder.GetFoldersAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFolder
的用法示例。
在下文中一共展示了StorageFolder.GetFoldersAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllFiles
private async void GetAllFiles(StorageFolder folder, ObservableCollection<Song> songs)
{
foreach (StorageFile file in await folder.GetFilesAsync())
{
if(file.FileType == ".mp3")
{
var props = await file.Properties.GetMusicPropertiesAsync();
var image = await file.GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.MusicView);
var cover = new BitmapImage();
cover.SetSource(image);
Song song = new Song()
{
Name = props.Title,
Album = props.Album,
Artist = props.Artist,
Cover = cover,
File = file
};
songs.Add(song);
}
}
foreach (StorageFolder subfolder in await folder.GetFoldersAsync())
{
GetAllFiles(subfolder, songs);
}
}
示例2: getFiles
public async Task getFiles(List<StorageFile> list, StorageFolder parent)
{ //get all files of type folder search use Recursion
foreach (var item in await parent.GetFilesAsync())
{
list.Add(item);
}
foreach (var item in await parent.GetFoldersAsync())
await getFiles(list, item);
}
示例3: getFiles
public async Task getFiles(List<StorageFile> list, StorageFolder parent)
{
foreach (var item in await parent.GetFilesAsync())
{
list.Add(item);
}
foreach (var item in await parent.GetFoldersAsync())
await getFiles(list, item);
}
示例4: MergeFolders
internal async static Task MergeFolders(StorageFolder source, StorageFolder target)
{
foreach (StorageFile sourceFile in await source.GetFilesAsync())
{
await sourceFile.CopyAndReplaceAsync(await target.CreateFileAsync(sourceFile.Name, CreationCollisionOption.OpenIfExists));
}
foreach (StorageFolder sourceDirectory in await source.GetFoldersAsync())
{
StorageFolder nextTargetSubDir = await target.CreateFolderAsync(sourceDirectory.Name, CreationCollisionOption.OpenIfExists);
await MergeFolders(sourceDirectory, nextTargetSubDir);
}
}
示例5: folderInitialisation
private async void folderInitialisation(StorageFolder picturesFolder)
{
IReadOnlyList<StorageFolder> folderList = await picturesFolder.GetFoldersAsync();
StringBuilder folderString = new StringBuilder(picturesFolder.Name + "\n\n");
foreach (StorageFolder folder in folderList)
{
folderString.AppendLine(" " + folder.DisplayName + "\\");
}
folderText.Text = folderString.ToString();
}
示例6: retrieveFilesInFolders
private async Task retrieveFilesInFolders(ObservableCollection<StorageFile> list,StorageFolder parent)
{
foreach (var item in await parent.GetFilesAsync())
{
if (item.FileType == ".mp3")
list.Add(item);
}
foreach (var item in await parent.GetFoldersAsync())
{
await retrieveFilesInFolders(list, item);
}
}
示例7: GetFileCountInWhitelist
/// <summary>
/// Returns the number of files within the Oxford Whitelist
/// </summary>
public static async Task<int> GetFileCountInWhitelist(StorageFolder folder)
{
int fileCount = 0;
fileCount += (await folder.GetFilesAsync()).Count;
var subFolders = await folder.GetFoldersAsync();
foreach(var subFolder in subFolders)
{
fileCount += (await subFolder.GetFilesAsync()).Count;
}
return fileCount;
}
示例8: RetriveFilesInFolder
// first - a method to retrieve files from folder recursively
private static async Task RetriveFilesInFolder(List<StorageFile> list, StorageFolder parent)
{
list.AddRange((await parent.GetFilesAsync()).Where(p =>
p.FileType == ".wma"
|| p.FileType == ".flac"
|| p.FileType == ".m4a"
|| p.FileType == ".mp3"));
//avoiding DRM folder of xbox music
foreach (var folder in (await parent.GetFoldersAsync()).Where(folder =>
folder.Name != "Xbox Music" && folder.Name != "Subscription Cache" && folder.Name != "Podcasts"))
{
await RetriveFilesInFolder(list, folder);
}
}
示例9: _getAllFilesInFolderRecurse
async Task<List<string>> _getAllFilesInFolderRecurse(StorageFolder currentFolder, string topFolder)
{
List<string> files = new List<string>();
foreach (var f in await currentFolder.GetFoldersAsync())
{
files.AddRange(await _getAllFilesInFolderRecurse(f, topFolder));
}
var filesResult = await currentFolder.GetFilesAsync();
var filesString = filesResult.Select(_ => _.Path.Replace(topFolder, "").Trim('\\')).ToList();
files.AddRange(filesString);
return files;
}
示例10: DeleteFolderRecursivelyAsync
private async Task DeleteFolderRecursivelyAsync(StorageFolder folder)
{
IReadOnlyList<StorageFolder> folders = await folder.GetFoldersAsync();
if (folders.Count > 0)
{
foreach (StorageFolder subFolder in folders)
{
await DeleteFolderRecursivelyAsync(subFolder);
}
}
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync();
foreach (StorageFile file in files)
{
await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
}
}
示例11: GetAllFolders
public async void GetAllFolders(StorageFolder KnownFolders)
{
IReadOnlyList<StorageFolder> folderList = await KnownFolders.GetFoldersAsync();
// Pluck off meta data from folders
int id = 0;
foreach (StorageFolder folder in folderList)
{
Folder Folder = new Folder();
Folder.Id = id;
Folder.Name = folder.Name;
Folder.Path = folder.Path;
Folder.FolderFile = folder;
Folders.Add(Folder);
id++;
}
}
示例12: FindJSBundleInUpdateContents
internal async static Task<string> FindJSBundleInUpdateContents(StorageFolder updateFolder, string expectedFileName)
{
foreach (StorageFile file in await updateFolder.GetFilesAsync())
{
string fileName = file.Name;
if (fileName.Equals(expectedFileName))
{
return fileName;
}
}
foreach (StorageFolder folder in await updateFolder.GetFoldersAsync())
{
string mainBundlePathInSubFolder = await FindJSBundleInUpdateContents(folder, expectedFileName);
if (mainBundlePathInSubFolder != null)
{
return Path.Combine(folder.Name, mainBundlePathInSubFolder);
}
}
return null;
}
示例13: ListFilesInFolder
public async Task ListFilesInFolder(StorageFolder folder)
{
var foldersInFolder = await folder.GetFoldersAsync();
foreach (StorageFolder currentChildFolder in foldersInFolder)
{
await ListFilesInFolder(currentChildFolder);
}
var filesInFolder = await folder.GetFilesAsync();
foreach (StorageFile currentFile in filesInFolder)
{
if (currentFile.ContentType.IsImageFormat())
{
var picture = new Picture(currentFile.Name, currentFile.DateCreated.DateTime, currentFile.Path);
if (!pictures.Contains(picture))
{
pictures.Add(picture);
await picture.LoadImageAsync();
}
}
}
}
示例14: ZipFolderContents
/// <summary>
/// ZipFolder and its sub folders
/// </summary>
/// <param name="tcpSocket"></param>
async private static Task ZipFolderContents(StorageFolder sourceFolder, ZipArchive archive, string baseDirPath)
{
IReadOnlyList<StorageFile> files = await sourceFolder.GetFilesAsync();
foreach (StorageFile file in files)
{
ZipArchiveEntry readmeEntry = archive.CreateEntry(GetCompressedFileName(baseDirPath, file));
byte[] buffer = WindowsRuntimeBufferExtensions.ToArray(await FileIO.ReadBufferAsync(file));
// And write the contents to it
using (Stream entryStream = readmeEntry.Open())
{
await entryStream.WriteAsync(buffer, 0, buffer.Length);
}
}
IReadOnlyList<StorageFolder> subFolders = await sourceFolder.GetFoldersAsync();
if (subFolders.Count() == 0) return;
foreach (StorageFolder subfolder in subFolders)
await ZipFolderContents(subfolder, archive, baseDirPath);
}
示例15: BrowseFolder
public async System.Threading.Tasks.Task<uint> BrowseFolder(StorageFolder folder)
{
// LogMessage("Discover folder Name: " + folder.Name + " Path: " + folder.Path + " files: [" + fileDiscovered + "] folders: [" + folderDiscovered + "]");
folderDiscovered++;
if (ProgressEvent != null)
ProgressEvent(folderDiscovered);
await System.Threading.Tasks.Task.Delay(100);
try
{
if (discoverCancelToken != null)
if (discoverCancelToken.Token.IsCancellationRequested)
discoverCancelToken.Token.ThrowIfCancellationRequested();
IReadOnlyList<StorageFolder> folders = await folder.GetFoldersAsync(CommonFolderQuery.DefaultQuery);
foreach (var f in folders)
{
if (discoverCancelToken != null)
if (discoverCancelToken.Token.IsCancellationRequested)
discoverCancelToken.Token.ThrowIfCancellationRequested();
uint value = await BrowseFolder(f);
}
}
catch (Exception e)
{
LogMessage("Discover folder exception: " + folder.Path + " Exception:" + e.Message);
}
uint currentFilesDiscovered = fileDiscovered;
try
{
if (discoverCancelToken != null)
if (discoverCancelToken.Token.IsCancellationRequested)
discoverCancelToken.Token.ThrowIfCancellationRequested();
// IReadOnlyList<StorageFile> files = await folder.GetFilesAsync(CommonFileQuery.OrderByName);
IReadOnlyList<StorageFile> files = await folder.GetFilesAsync(CommonFileQuery.DefaultQuery);
foreach (var f in files)
{
if (discoverCancelToken != null)
if (discoverCancelToken.Token.IsCancellationRequested)
discoverCancelToken.Token.ThrowIfCancellationRequested();
string path = await GetPath(f);
string extension = f.FileType;
foreach (string e in extensionArray)
{
if (extension.EndsWith(e, StringComparison.CurrentCultureIgnoreCase))
{
if (!defaultMediaDictionary.ContainsKey(path))
{
MediaLibraryItem mli = new MediaLibraryItem(path);
defaultMediaDictionary.Add(path, mli);
fileDiscovered = (uint)defaultMediaDictionary.Count;
}
UpdateUI();
//statusValue.Text = fileDiscovered.ToString() + " files discovered";
// LogMessage("Discover file name: " + f.Name + " path: " + path);
break;
}
}
}
}
catch (Exception e)
{
LogMessage("Discover files exception: " + folder.Path + " Exception:" + e.Message);
}
if (currentFilesDiscovered != fileDiscovered)
{
UpdateCounter();
}
return fileDiscovered;
}