예제 #1
0
        public Task <FileInfo[]> GetFilesAsync(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path), "Can't be null");
            }

            var fullPath = Path.Combine(_storageInfo.StoragePath, path.EscapePath());

            if (!Directory.Exists(fullPath))
            {
                return(Task.FromResult(new FileInfo[0]));
            }

            var fileNames    = Directory.GetFiles(fullPath, "*", SearchOption.AllDirectories);
            var fileInfoList = new List <FileInfo>();

            foreach (var fileName in fileNames)
            {
                var localFileInfo = new System.IO.FileInfo(fileName);
                fileInfoList.Add(localFileInfo.ToFileInfo(_storageInfo));
            }

            return(Task.FromResult(fileInfoList.ToArray()));
        }
예제 #2
0
        public Task <FileInfo> GetFileAsync(string pathToFile)
        {
            if (string.IsNullOrWhiteSpace(pathToFile))
            {
                throw new ArgumentNullException(nameof(pathToFile), "Can't be null or empty");
            }

            var fullPath = Path.Combine(_storageInfo.StoragePath, pathToFile.EscapePath());

            if (!File.Exists(fullPath))
            {
                throw new FileNotFoundException("File not found", fullPath);
            }

            var file     = new System.IO.FileInfo(fullPath);
            var fileInfo = file.ToFileInfo(_storageInfo);

            return(Task.FromResult(fileInfo));
        }
예제 #3
0
        internal static FileInfo ToFileInfo(this System.IO.FileInfo info, LocalStorageInfo storageInfo)
        {
            var relaivePath = info.FullName.Replace(storageInfo.StoragePath, "").EscapePath().StripPath();

            return(new FileInfo(relaivePath, info.Length, info.CreationTimeUtc));
        }