Ejemplo n.º 1
0
        private static ClipboardVirtualFileData ReadFileDrop(string[] data)
        {
            string[]            files = data;
            DirectoryAttributes root  = new DirectoryAttributes("", new List <FileAttributes>(), new List <DirectoryAttributes>(), "");
            int fCount = 0;

            foreach (var file in files)
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(file))
                    {
                        continue;
                    }

                    System.IO.FileAttributes fa = System.IO.File.GetAttributes(file);
                    if (fa.HasFlag(System.IO.FileAttributes.Directory))
                    {
                        DirectoryAttributes di = new DirectoryAttributes(new DirectoryInfo(file));
                        root.SubFolders.Add(di);

                        foreach (var baseFile in Directory.GetFiles(file))
                        {
                            FileAttributes df = new FileAttributes(new FileInfo(baseFile));
                            df.RelativePath = Path.Combine(di.Name, df.FileName);
                            di.Files.Add(df);
                        }
                    }
                    else
                    {
                        root.Files.Add(new FileAttributes(new FileInfo(file)));
                    }
                }
                catch (Exception ex)
                {
                    ISLogger.Write("An error occurred while reading attributes for {0}. File not copied: {1}", file, ex.Message);
                    ISLogger.Write(ex.StackTrace);
                }
            }

            foreach (var folder in root.SubFolders)
            {
                AddDirectoriesRecursive(folder, folder.Name, ref fCount);
            }

            return(new ClipboardVirtualFileData(root));
        }
Ejemplo n.º 2
0
        private static ClipboardVirtualFileData ReadFileDrop(System.Windows.Forms.IDataObject data)
        {
            string[]            files = (string[])data.GetData(DataFormats.FileDrop);
            DirectoryAttributes root  = new DirectoryAttributes("", new List <FileAttributes>(), new List <DirectoryAttributes>(), "");
            int fCount = 0;

            foreach (var file in files)
            {
                try
                {
                    System.IO.FileAttributes fa = System.IO.File.GetAttributes(file);
                    if (fa.HasFlag(System.IO.FileAttributes.Directory))
                    {
                        DirectoryAttributes di = new DirectoryAttributes(new DirectoryInfo(file));
                        root.SubFolders.Add(di);

                        foreach (var baseFile in Directory.GetFiles(file))
                        {
                            FileAttributes df = new FileAttributes(new FileInfo(baseFile));
                            df.RelativePath = Path.Combine(di.Name, df.FileName);
                            di.Files.Add(df);
                        }
                    }
                    else
                    {
                        root.Files.Add(new FileAttributes(new FileInfo(file)));
                    }
                }
                catch (ClipboardTranslationException ex)
                {
                    ISLogger.Write("An error occurred while reading attributes for {0}. File not copied\n{1}", file, ex.Message);
                }
            }

            foreach (var folder in root.SubFolders)
            {
                AddDirectoriesRecursive(folder, folder.Name, ref fCount);
            }

            return(new ClipboardVirtualFileData(root));
        }