當前位置: 首頁>>代碼示例>>C#>>正文


C# StorageFolder.GetFilesAsync方法代碼示例

本文整理匯總了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);
            }
        }
開發者ID:jeslas,項目名稱:UWP-Playground,代碼行數:27,代碼來源:MediaLibrary.xaml.cs

示例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") -&gt; "naruto"
        /// GetNewFileName(folder, "naruto") -&gt; "naruto_1"
        /// GetNewFileName(folder, "naruto") -&gt; "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;
            }
        }
開發者ID:molant,項目名稱:MangApp,代碼行數:44,代碼來源:FileSystemUtilities.cs

示例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);
     }
 }
開發者ID:zirakai,項目名稱:NyxoWp,代碼行數:9,代碼來源:MusicControl.xaml.cs

示例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;
        }
開發者ID:nzall,項目名稱:GameRoulette,代碼行數:9,代碼來源:GameRouletteModel.cs

示例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);
 }
開發者ID:sikyurabmt,項目名稱:HQL,代碼行數:9,代碼來源:MainPage.xaml.cs

示例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);
 }
開發者ID:sikyurabmt,項目名稱:HQL,代碼行數:9,代碼來源:MusicManager.cs

示例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);
            }
        }
開發者ID:sushantgoel,項目名稱:AlbumMatchGame,代碼行數:13,代碼來源:MainPage.xaml.cs

示例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);
     }
 }
開發者ID:cmcewen,項目名稱:react-native-code-push,代碼行數:13,代碼來源:FileUtils.cs

示例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;
 }
開發者ID:prebenh,項目名稱:MobileVikings,代碼行數:19,代碼來源:Tweets.cs

示例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)
         });
             
     }
 }
開發者ID:ma1982en,項目名稱:curly-octo-pancake,代碼行數:14,代碼來源:ChoosingViewModel.cs

示例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);
            }
        }
開發者ID:jayharry28,項目名稱:Audiotica,代碼行數:16,代碼來源:LocalMusicHelper.cs

示例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;
        }
開發者ID:jakkaj,項目名稱:Xamling-Core,代碼行數:15,代碼來源:LocalStorage.cs

示例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;
        }
開發者ID:vishalishere,項目名稱:Facial-Recognition-Door,代碼行數:18,代碼來源:FaceApiUtils.cs

示例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);
        }
開發者ID:zirakai,項目名稱:NyxoWp,代碼行數:16,代碼來源:GetPictures.cs

示例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);
            }
        }
開發者ID:bcl-lab-apps,項目名稱:EMRGENE,代碼行數:17,代碼來源:FolderObjectStore.cs


注:本文中的Windows.Storage.StorageFolder.GetFilesAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。