本文整理汇总了C#中Windows.Storage.StorageFolder.GetFilesAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFolder.GetFilesAsync方法的具体用法?C# StorageFolder.GetFilesAsync怎么用?C# StorageFolder.GetFilesAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFolder
的用法示例。
在下文中一共展示了StorageFolder.GetFilesAsync方法的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: GetNewFileName
/// <summary>
/// Gets a new filename which starts as the base filename parameter, but has a different end part.
/// </summary>
/// <param name="folder">The folder where the name will be checked.</param>
/// <param name="baseFileName">Base filename to use as root.</param>
/// <returns>
/// The new filename.
/// </returns>
/// <example>
/// In case that "naruto" does not exist in folder.
/// GetNewFileName(folder, "naruto") -> "naruto"
/// GetNewFileName(folder, "naruto") -> "naruto_1"
/// GetNewFileName(folder, "naruto") -> "naruto_2"
/// ...
/// </example>
public static string GetNewFileName(StorageFolder folder, string baseFileName)
{
try
{
var names = folder.GetFilesAsync()
.AsTask().Result
.Select(f => Path.GetFileNameWithoutExtension(f.Name));
string possibleName = baseFileName;
int index = 1;
while (true)
{
if (names.Any(n => n.Equals(possibleName, StringComparison.CurrentCultureIgnoreCase)))
{
possibleName = baseFileName + index++;
}
else
{
break;
}
}
return possibleName;
}
catch (Exception)
{
return baseFileName;
}
}
示例3: GetMusics
private async void GetMusics(StorageFolder folder)
{
// Get all the songs in the folder past in parameter
foreach (var item in await folder.GetFilesAsync())
{
if (item.FileType == ".mp3")
allSongs.Add(item);
}
}
示例4: SelectGameExecutables
public async Task<int> SelectGameExecutables(StorageFolder folder)
{
IEnumerable<StorageFile> retrievedFiles = await folder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName);
var fileCount = retrievedFiles.Count();
Files = retrievedFiles.Where(file => ValidateFile(file)).ToList();
return Files.Count;
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
}
示例8: 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);
}
}
示例9: Initialize
/// <summary>
/// Initializes this instance.
/// Load the images of Mobile Vikings team.
/// </summary>
/// <returns></returns>
public async Task<bool> Initialize()
{
try
{
var assets = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets");
_folder = await assets.GetFolderAsync("People");
_files = await _folder.GetFilesAsync();
}
catch (Exception ex)
{
return false;
}
return true;
}
示例10: LoadImagesFromDirectory
private async void LoadImagesFromDirectory(StorageFolder imagesdirectory)
{
Images.Clear();
var files = await imagesdirectory.GetFilesAsync();
foreach (var file in files)
{
Images.Add(new PhotoDto
{
ID = Guid.NewGuid(),
Image = await LoadImage(file)
});
}
}
示例11: 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);
}
}
示例12: _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;
}
示例13: 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;
}
示例14: GetAllPictures
public async void GetAllPictures(StorageFolder folder)
{
// Get all the Pictures in the folder past in parameter
foreach (var item in await folder.GetFilesAsync())
{
if (item.FileType == ".jpg" || item.FileType == ".jpeg"
|| item.FileType == ".tif" || item.FileType == ".tiff"
|| item.FileType == ".png" || item.FileType == ".gif"
|| item.FileType == ".bmp" || item.FileType == ".dib"
|| item.FileType == ".wdp")
allPictures.Add(item);
}
// Pluck off meta data from pictures
GetInformationPictures(allPictures);
}
示例15: 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);
}
}