本文整理汇总了C#中Windows.Storage.StorageFolder.GetItemsAsync方法的典型用法代码示例。如果您正苦于以下问题:C# StorageFolder.GetItemsAsync方法的具体用法?C# StorageFolder.GetItemsAsync怎么用?C# StorageFolder.GetItemsAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Storage.StorageFolder
的用法示例。
在下文中一共展示了StorageFolder.GetItemsAsync方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadFolder
private async Task LoadFolder(StorageFolder folder, DateTime lastSync)
{
if (isCanceled) return;
IReadOnlyList<IStorageItem> fileList = await folder.GetItemsAsync();
foreach (IStorageItem storageItem in fileList)
{
if (storageItem.IsOfType(StorageItemTypes.File))
{
StorageFile storageFile = DebugHelper.CastAndAssert<StorageFile>(storageItem);
await LoadFile(storageFile);
}
else if (storageItem.IsOfType(StorageItemTypes.Folder))
{
StorageFolder storageFolder = DebugHelper.CastAndAssert<StorageFolder>(storageItem);
BasicProperties basicProperties = await storageFolder.GetBasicPropertiesAsync();
DateTime candidateTime = basicProperties.DateModified.UtcDateTime;
if (candidateTime > lastSync)
{
await LoadFolder(storageFolder, lastSync);
}
}
}
}
示例2: DeleteFolder
public static async Task<bool> DeleteFolder(StorageFolder folder)
{
var folders = await folder.GetItemsAsync();
for (int i = 0; i < folders.Count; i++)
{
DeletItem(folders[i]);
}
return true;
}
示例3: ClearFiles
public static async Task ClearFiles(StorageFolder folder)
{
try
{
foreach (IStorageItem item in await folder.GetItemsAsync())
{
if (item.IsOfType(StorageItemTypes.Folder))
{
await ClearFiles((StorageFolder) item);
}
else
{
await item.DeleteAsync();
}
}
}
catch (FileNotFoundException)
{
}
}
示例4: GetAllFiles
private async Task GetAllFiles(StorageFolder storageFolder, List<StorageFile> musicFiles)
{
foreach (var item in await storageFolder.GetItemsAsync())
if (item is StorageFile)
{
var file = item as StorageFile;
if (file.ContentType.StartsWith("audio") && !file.ContentType.EndsWith("url"))
musicFiles.Add(file);
}
else
{
var folder = item as StorageFolder;
await this.GetAllFiles(folder, musicFiles);
}
}
示例5: GetFilesFromSubFolders
private static async Task GetFilesFromSubFolders(StorageFolder folder, List<StorageFile> files)
{
try
{
var items = await folder.GetItemsAsync();
foreach (IStorageItem storageItem in items)
{
if (storageItem.IsOfType(StorageItemTypes.Folder))
await GetFilesFromSubFolders(storageItem as StorageFolder, files);
else if (storageItem.IsOfType(StorageItemTypes.File))
{
var file = storageItem as StorageFile;
if (VLCFileExtensions.VideoExtensions.Contains(file.FileType.ToLower()))
{
files.Add(file);
}
}
}
}
catch (Exception e)
{
ExceptionHelper.CreateMemorizedException("VideoLibraryManagement.GetFilesFromSubFolders", e);
}
}
示例6: FilesNumber
private async Task FilesNumber(StorageFolder cartella)
{
var Items = await cartella.GetItemsAsync();
foreach(IStorageItem Item in Items)
{
if(Item.IsOfType(StorageItemTypes.Folder))
{
await FilesNumber((StorageFolder)Item);
}
else if(Item.IsOfType(StorageItemTypes.File))
{
file_count++;
BasicProperties bp = await ((StorageFile)Item).GetBasicPropertiesAsync();
file_size+= bp.Size;
}
}
}
示例7: CreateBackup
public static async Task<byte[]> CreateBackup(StorageFolder folder)
{
using (var autcpStream = new MemoryStream())
{
// add header now
AddHeader(autcpStream);
using (var zipArchive = new ZipArchive(autcpStream, ZipArchiveMode.Create))
{
var filesToCompress = await folder.GetItemsAsync();
foreach (var item in filesToCompress)
{
var files = new List<StorageFile>();
if (item is StorageFile)
{
var file = item as StorageFile;
if (file.FileType == ".autcp" || file.Name.ToLower().StartsWith("xam")
|| file.Name.StartsWith("_"))
{
continue;
}
files.Add(file);
}
else if (item is StorageFolder)
{
var name = (item as StorageFolder).Name;
if (name == "SOMA" || name == "Logs" || name == "AdMediator" || name == "artists" || name == "artworks")
{
continue;
}
files.AddRange(await (item as StorageFolder).GetFilesAsync());
}
foreach (var file in files)
{
var buffer = await FileIO.ReadBufferAsync(file);
if (buffer.Length == 0)
{
continue;
}
var bytes = buffer.ToArray();
var path = file.Path.Replace(folder.Path + "\\", string.Empty).Replace("\\", "/");
var entry = zipArchive.CreateEntry(path, CompressionLevel.Optimal);
using (var entryStream = entry.Open())
{
await entryStream.WriteAsync(bytes, 0, bytes.Length);
await entryStream.FlushAsync();
}
}
}
}
return autcpStream.ToArray();
}
}
示例8: GetFilesAsync
private IObservable<StorageFile> GetFilesAsync(StorageFolder folder)
{
var obsItems = folder.GetItemsAsync().ToObservable();
var files = (from item in obsItems
from i in item
select i is StorageFile ? Observable.Return((StorageFile)i) : GetFilesAsync((StorageFolder)i))
.SelectMany(i => i);
return files;
}
示例9: CopyFolder
/// <summary>
/// Copy a <see cref="StorageFolder"/> and its content to a specified directory
/// </summary>
/// <param name="source">the source folder</param>
/// <param name="destination">the destination folder where create the copy</param>
/// <param name="directoryName">the copy directory</param>
/// <returns></returns>
public async Task<bool> CopyFolder(StorageFolder source, StorageFolder destination, string directoryName)
{
//using (await InstanceLock.LockAsync())
//{
var isCopied = true;
try
{
directoryName = directoryName.Replace("/", "\\");
await CreateDirectory(destination, directoryName);
var folderDest = await destination.GetFolderAsync(directoryName);
if (folderDest != null)
{
var items = await source.GetItemsAsync();
foreach (var item in items)
{
if (item.IsOfType(StorageItemTypes.File) == true)
{
isCopied = await CopyFile(source, folderDest, item.Name);
}
else if (item.IsOfType(StorageItemTypes.Folder) == true)
{
isCopied = await CopyFolder(source, folderDest, item.Name);
}
if (isCopied == false)
{
throw new Exception("Fail to copy item");
}
}
}
else
{
throw new Exception("Fail to create new directory");
}
}
catch
{
isCopied = false;
}
return isCopied;
//}
}
示例10: SearchAllinFolder
public static async Task<List<IStorageFile>> SearchAllinFolder(StorageFolder tempFolder)
{
try
{
IReadOnlyList<IStorageItem> tempList = await tempFolder.GetItemsAsync();
List<IStorageFile> finalList = new List<IStorageFile>();
if (tempList.Count == 0)
return finalList;
foreach (var item in tempList)
{
if (item is StorageFolder)
{
finalList.AddRange(await SearchAllinFolder((StorageFolder)item));
}
if (item is StorageFile)
{
if (tempTypeStrings.Contains(((StorageFile)item).FileType))
{
finalList.Add((StorageFile)item);
}
}
}
return finalList;
}
catch (Exception)
{
return new List<IStorageFile>();
}
}
示例11: DeleteFolderContentAsync
public static async Task DeleteFolderContentAsync(StorageFolder folder)
{
var items = await folder.GetItemsAsync();
foreach (var storageItem in items)
await storageItem.DeleteAsync();
}
示例12: showSequenceForFolder
private async void showSequenceForFolder(StorageFolder sf, bool repeat)
{
if (stopSequence) return;
IReadOnlyList<IStorageItem> snapList = await sf.GetItemsAsync();
try
{
for (int i=0; i < snapList.Count; i++)
{
StorageFile currFile = await sf.GetFileAsync(snapList[i].Name);
BitmapImage bmpimg = await ImageController.GetImage(currFile);
sequenceElement.Source = bmpimg;
screensaverView.Source = bmpimg;
await Task.Delay(TimeSpan.FromMilliseconds(150));
}
}
catch (Exception ex)
{
addMessage("exception caught in sequence: " + ex.Message);
}
if (repeat) this.showSequenceForFolder(sf,repeat);
}
示例13: ScanDirectoryAsync
private async Task ScanDirectoryAsync(StorageFolder storageFolder, bool doSha1, IObserver<string> starts, IObserver<FileInfo> completes)
{
foreach (var entry in await storageFolder.GetItemsAsync()) {
var folder = entry as StorageFolder; // folder
if (folder != null) {
starts.OnNext(folder.Name);
var innerStarts = new Subject<string>();
var innerCompletes = new Subject<FileInfo>();
var _ = Task.Run(() => ScanDirectoryAsync(folder, false, innerStarts, innerCompletes));
var totalSize = await innerStarts
.Zip(innerCompletes, (s, f) => (double)f.Size)
.Sum(x => x).FirstAsync();
completes.OnNext(new FileInfo { Name = folder.Name, Size = (ulong)totalSize });
}
var file = entry as StorageFile; // file
if (file != null) {
starts.OnNext(file.Name);
var fileInfo = await ScanFile(file, doSha1).ConfigureAwait(false);
completes.OnNext(fileInfo);
}
}
starts.OnCompleted();
completes.OnCompleted();
}