Exemplo n.º 1
0
        public async Task RecursivelyDeleteDirectoryAsync(string path)
        {
            List <MonitoredFolderItem> mininfo = PinvokeFilesystem.GetMinInfo(path);

            foreach (MonitoredFolderItem item in mininfo)
            {
                string itempath = System.IO.Path.Combine(item.ParentFolderPath, item.Name);
                if (item.attributes.HasFlag(System.IO.FileAttributes.Directory))
                {
                    await RecursivelyDeleteDirectoryAsync(itempath);
                }
                else
                {
                    await Task.Run(() => { PinvokeFilesystem.DeleteFileFromApp(@"\\?\" + itempath); });
                }
            }
            await Task.Run(() => { PinvokeFilesystem.RemoveDirectoryFromApp(@"\\?\" + path); });
        }
Exemplo n.º 2
0
        private async Task <bool> MoveFolderAsync(string folder, string destination, bool firstcall = true)
        {
            List <MonitoredFolderItem> mininfo = PinvokeFilesystem.GetMinInfo(folder);

            foreach (MonitoredFolderItem item in mininfo)
            {
                string itempath   = System.IO.Path.Combine(item.ParentFolderPath, item.Name);
                string targetpath = System.IO.Path.Combine(destination, item.Name);
                if (item.attributes.HasFlag(System.IO.FileAttributes.Directory))
                {
                    await Task.Run(() =>
                    {
                        PinvokeFilesystem.CreateDirectoryFromApp(@"\\?\" + targetpath, IntPtr.Zero);
                    });
                    await MoveFolderAsync(itempath, targetpath, false);
                }
                else
                {
                    //move file
                    await Task.Run(() =>
                    {
                        PinvokeFilesystem.CopyFileFromApp(@"\\?\" + itempath, @"\\?\" + targetpath, false);
                        PinvokeFilesystem.DeleteFileFromApp(@"\\?\" + itempath);
                    });
                }
            }
            mininfo = PinvokeFilesystem.GetMinInfo(folder);
            if (mininfo.Count() == 0)
            {
                await Task.Run(() => { PinvokeFilesystem.RemoveDirectoryFromApp(@"\\?\" + folder); });

                if (firstcall)
                {
                    MainPage.Current.RefreshStorage();
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }