예제 #1
0
        public IEnumerable <string> GetExplorerSelectedFiles()
        {
            if (_lastExplorerWindowPtr == IntPtr.Zero)
            {
                return(new string[0]);
            }
            try
            {
                var selected = new List <string>();
                foreach (var window in this.GetShellWindows())
                {
                    if (!IsRealExplorerWindow(window))
                    {
                        continue;
                    }
                    if (window.HWND == (int)_lastExplorerWindowPtr)
                    {
                        Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                        foreach (Shell32.FolderItem item in items)
                        {
                            selected.Add(item.Path);
                        }
                    }
                }
                return(selected);
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(ex.ToString());
            }

            return(new string[0]);
        }
예제 #2
0
        private static void ChangeLinkTarget(string shortcutFullPath, string newTarget)
        {
            // Load the shortcut.
            Shell32.Folder      folder = GetShell32NameSpaceFolder(Path.GetDirectoryName(shortcutFullPath));
            Shell32.FolderItems items  = folder.Items();
            IEnumerator         en     = items.GetEnumerator();

            Shell32.FolderItem item = null;
            while (en.MoveNext())
            {
                item = en.Current as Shell32.FolderItem;
                if (item == null)
                {
                    continue;
                }

                if (item.Name == Path.GetFileName(shortcutFullPath))
                {
                    break;
                }
            }

            if (item == null || !item.IsLink)
            {
                return;
            }

            Shell32.ShellLinkObject currentLink = (Shell32.ShellLinkObject)item.GetLink;

            // Assign the new path here. This value is not read-only.
            currentLink.Path = newTarget;

            // Save the link to commit the changes.
            currentLink.Save();
        }
예제 #3
0
        // Llena el listbox con los documentos que estan seleccionados

        public static void getsSelectedPDFFiles()
        {
            string filename;

            foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows())
            {
                filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower();

                if (filename.ToLowerInvariant() == "explorer")
                {
                    Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();

                    foreach (Shell32.FolderItem item in items)
                    {
                        Console.WriteLine(item.Path);
                        // si la extension es .pdf la agrega a la lista de documentos a combinar

                        string fileExtension = getFileExtension(item.Path);

                        Console.WriteLine(item.Path);

                        if (fileExtension == ".pdf")
                        {
                            Archivo archivo = new Archivo();

                            archivo.Path      = item.Path;
                            archivo.Name      = getFileName(item.Path);;
                            archivo.Extension = fileExtension;

                            listaArchivos.Add(archivo);
                        }
                    }
                }
            }
        }
예제 #4
0
        private static void CheckForSubDirs(TreeNode tn, ImageList imageList)
        {
            if (tn.Nodes.Count == 0)
            {
                try {
                    // create dummy nodes for any subfolders that have further subfolders
                    Shell32.FolderItem folderItem = (Shell32.FolderItem)tn.Tag;
                    Shell32.Folder     folder     = (Shell32.Folder)folderItem.GetFolder;

                    bool hasFolders             = false;
                    Shell32.FolderItems sfItems = folder.Items();
                    foreach (Shell32.FolderItem item in sfItems)
                    {
                        if (item.IsFileSystem && item.IsFolder && !item.IsBrowsable)
                        {
                            hasFolders = true;
                            break;
                        }
                    }
                    if (hasFolders)
                    {
                        TreeNode ntn = new TreeNode();
                        ntn.Tag = "DUMMYNODE";
                        tn.Nodes.Add(ntn);
                    }
                } catch { }
            }
        }
예제 #5
0
        private void FindFieldContent()
        {
            textBoxTitle.Text = FindTaskParts(out string[] titles, out string[][] subtasks);

            Shell32.Shell       shell  = new Shell32.Shell();
            Shell32.Folder      folder = shell.NameSpace(FIELD_PIC_PATH);
            Shell32.FolderItems items  = folder.Items();

            for (int i = 0; i < items.Count; i++)
            {
                var fileName = folder.GetDetailsOf(items.Item(i), 0);
                DecompilePicName(Path.GetFileNameWithoutExtension(fileName), out var position, out var taskNumber);

                fields[position - 1].TaskNumbers.Add(taskNumber);
                fields[position - 1].Title = titles[position - 1];

                if (subtasks[position - 1].Length < taskNumber)
                {
                    MessageBox.Show("Nem tartozik feladat a képhez:" + fileName);
                    fields[position - 1].Tasks.Add("");
                }
                else
                {
                    fields[position - 1].Tasks.Add(subtasks[position - 1][taskNumber - 1]);
                }

                fields[position - 1].Paths.Add(FIELD_PIC_PATH + fileName);
            }
        }
예제 #6
0
        public static int NumberOfSelectedFiles; // seçili dosyaların sayısını tutacak

        public static List <string> FilesAndFolders(String ActiveWindowPath)
        {
            string        filename;
            List <string> explorerItems = new List <string>();

            foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows()) // Tüm Açık Klasörler i tarar
            {
                filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower();

                if (filename.ToLowerInvariant() == "explorer")
                {
                    Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();

                    foreach (Shell32.FolderItem item in items)
                    {
                        if (ActiveWindowPath == Path.GetDirectoryName(item.Path))
                        {
                            explorerItems.Add(item.Path);
                            //string test = ((Shell32.IShellFolderViewDual2)window.Document).FocusedItem.Path;
                            // MessageBox.Show(item.Path);
                        }
                    }
                }
            }
            return(explorerItems);
        }
예제 #7
0
        private static String[] getSelectedFileInExplorerWindow(IntPtr handle)
        {
            List <string> list         = new List <string>();
            ShellWindows  shellWindows = new SHDocVw.ShellWindows();

            foreach (InternetExplorer window in shellWindows)
            {
                if (window != null && window.HWND == (int)handle && ((Shell32.IShellFolderViewDual2)window.Document) != null)
                {
                    // The .FocusedItem is also available.
                    Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                    if (items != null)
                    {
                        foreach (object o in items)
                        {
                            Shell32.FolderItem item = o as Shell32.FolderItem;
                            if (item != null && item.Path != null)
                            {
                                list.Add(item.Path);
                            }
                        }
                    }
                }
            }
            return(list.ToArray());
        }
예제 #8
0
 /// <summary>
 /// Helper method for performing uncompression
 /// </summary>
 /// <param name="compressedFileName">Compressed file name</param>
 /// <param name="destination">destination to be extracted</param>
 public static void UnCompressZip(string compressedFileName, string destination)
 {
     Shell32.ShellClass  sc        = new Shell32.ShellClass();
     Shell32.Folder      SrcFlder  = sc.NameSpace(compressedFileName);
     Shell32.Folder      DestFlder = sc.NameSpace(destination);
     Shell32.FolderItems items     = SrcFlder.Items();
     DestFlder.CopyHere(items, 10);
 }
예제 #9
0
 /// <summary>
 /// 解压zip包
 /// </summary>
 /// <param name="zipFile">压缩包目录</param>
 /// <param name="destFolder">解压文件的目标存放目录</param>
 private void UnZip(string zipFile, string destFolder)
 {
     Shell32.ShellClass  sc         = new Shell32.ShellClass();
     Shell32.Folder      SrcFolder  = sc.NameSpace(zipFile);
     Shell32.Folder      DestFolder = sc.NameSpace(destFolder);
     Shell32.FolderItems items      = SrcFolder.Items();
     DestFolder.CopyHere(items, 20);
 }
예제 #10
0
        private void FillLocalView(Shell32.Folder folder)
        {
            this.Cursor = Cursors.WaitCursor;

            m_currentFolder = folder;

            // Notify that update begins
            LocalView.BeginUpdate();

            // Erase last view items
            LocalView.Items.Clear();

            // Erase previous lists image
            ImgListViewSmall.Images.Clear();
            ImgListViewLarge.Images.Clear();

            int idImage = 0;

            ListViewItem lvItem = new ListViewItem("..");

            lvItem.Tag = folder;

            LocalView.Items.Add(lvItem);

            Shell32.FolderItems items = folder.Items();

            // Folder enumeration
            foreach (Shell32.FolderItem item in items)
            {
                if (item.IsFolder)
                {
                    AddViewItem(item, ref idImage);
                }
            }

            // Other files
            foreach (Shell32.FolderItem item in items)
            {
                if (!item.IsFolder)
                {
                    AddViewItem(item, ref idImage);
                }
            }

            // End update view
            LocalView.EndUpdate();

            //ftpc.LocalFolder = folder.Title;

            this.Cursor = Cursors.Default;
        }
예제 #11
0
        private void InitializeIconFolder()
        {
            Shell32.Folder      FolderShell = m_Shell.NameSpace(Shell32.ShellSpecialFolderConstants.ssfWINDOWS);
            Shell32.FolderItems items       = FolderShell.Items();

            foreach (Shell32.FolderItem item in items)
            {
                if (item.IsFolder)
                {
                    m_IconFolder = ExtractIcon.GetIcon(item.Path, true);
                    break;
                }
            }
        }
예제 #12
0
 static void UnzipUpdateTo(string targerFolder)
 {
     try
     {
         Shell32.ShellClass  sc         = new Shell32.ShellClass();
         Shell32.Folder      SrcFolder  = sc.NameSpace(System.IO.Path.Combine(Application.StartupPath, "Update.zip"));
         Shell32.Folder      DestFolder = sc.NameSpace(targerFolder);
         Shell32.FolderItems items      = SrcFolder.Items();
         DestFolder.CopyHere(items, 20);
     }
     catch
     {
         return;
     }
 }
예제 #13
0
        static IEnumerable <string> GetItensSelecionadosExplorer(TipoComandoEnum tipoComando)
        {
            // get the active window
            IntPtr handle = NativeMethods.GetForegroundWindow();

            string        filename;
            List <string> lstItens = new List <string>();

            foreach (SHDocVw.InternetExplorer window in new SHDocVw.ShellWindows())
            {
                // match active window
                if (window.HWND != (int)handle)
                {
                    continue;
                }

                filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower();
                if (filename.ToLowerInvariant() == "explorer")
                {
                    Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                    foreach (Shell32.FolderItem item in items)
                    {
                        bool isArquivo = File.Exists(item.Path);

                        Trace.WriteLine("Este item: " + item.Path + " é um arquivo? R: " + isArquivo);

                        if (tipoComando == TipoComandoEnum.ArquivoCopiarNomeArquivo)
                        {
                            if (isArquivo)
                            {
                                lstItens.Add(item.Path);
                            }
                        }
                        else if (item.IsFolder)
                        {
                            lstItens.Add(item.Path);
                        }
                    }
                }
                else
                {
                    Trace.WriteLine("Não achei janela do explorer");
                }
            }
            return(lstItens.OrderBy(x => x));
        }
예제 #14
0
        /// <summary>
        /// Zip function calls Shell32, Interop.Shell32.dll is needed
        /// </summary>
        /// <param name="filesInFolder">Specify a folder containing the zip source files</param>
        /// <param name="zipFile">Specify the final zip file name, with ".zip" extension</param>
        public static void Compress(string filesInFolder, string zipFile)
        {
            if (filesInFolder == null || filesInFolder.Trim() == "")
            {
                return;
            }
            if (zipFile == null || zipFile.Trim() == "")
            {
                return;
            }
            if (!Directory.Exists(filesInFolder))
            {
                return;
            }

            DirectoryEx.DeleteEmptyDirectory(filesInFolder);

            Shell32.ShellClass sh = new Shell32.ShellClass();
            try
            {
                if (File.Exists(zipFile))
                {
                    File.Delete(zipFile);
                }
                //Create an empty zip file
                byte[] emptyzip = new byte[] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

                FileStream fs = File.Create(zipFile);
                fs.Write(emptyzip, 0, emptyzip.Length);
                fs.Flush();
                fs.Close();

                Shell32.Folder      srcFolder  = sh.NameSpace(filesInFolder);
                Shell32.Folder      destFolder = sh.NameSpace(zipFile);
                Shell32.FolderItems items      = srcFolder.Items();
                destFolder.CopyHere(items, SHFILEOPSTRUCT.FOF_SILENT | SHFILEOPSTRUCT.FOF_NOCONFIRMATION);
                while (items.Count != destFolder.Items().Count)
                {
                    Thread.Sleep(50);
                }
            }
            finally
            {
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(sh);
            }
        }
예제 #15
0
 /// <summary>
 /// 功能:解压zip格式的文件。
 /// </summary>
 /// <param name="zipFilePath">压缩文件路径</param>
 /// <param name="unZipDir">解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹</param>
 /// <param name="err">出错信息</param>
 /// <returns>解压是否成功</returns>
 public bool UnZipFile(string zipFilePath, string unZipDir, out string err)
 {
     err = "";
     if (zipFilePath.Length == 0)
     {
         err = "压缩文件不能为空!";
         return(false);
     }
     else if (!zipFilePath.EndsWith(".zip"))
     {
         err = "文件格式不正确!";
         return(false);
     }
     else if (!File.Exists(zipFilePath))
     {
         err = "压缩文件不存在!";
         return(false);
     }
     //解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹
     if (unZipDir.Length == 0)
     {
         unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath));
     }
     if (!unZipDir.EndsWith("\\"))
     {
         unZipDir += "\\";
     }
     if (!Directory.Exists(unZipDir))
     {
         Directory.CreateDirectory(unZipDir);
     }
     try
     {
         Shell32.ShellClass  sc         = new Shell32.ShellClass();
         Shell32.Folder      SrcFolder  = sc.NameSpace(zipFilePath);
         Shell32.Folder      DestFolder = sc.NameSpace(unZipDir);
         Shell32.FolderItems items      = SrcFolder.Items();
         DestFolder.CopyHere(items, 20);
     }
     catch (Exception ex)
     {
         err = ex.Message;
         return(false);
     }
     return(true);
 }//解压结束
예제 #16
0
        public static string ToZip(this DirectoryInfo d, string zipName = null, string zipExt = "zip", string basepath = null)
        {
            if (d == null)
            {
                throw new ArgumentNullException("Target Directory was null");
            }
            if (zipName == null)
            {
                zipName = d.Name;
            }
            if (basepath == null)
            {
                basepath = Environment.CurrentDirectory;
            }

            /// Inbuilt ZIP functions don't give a Dynamics CRM readable archive, but System ZIP function does
            // https://www.codeproject.com/Articles/12064/Compress-Zip-files-with-Windows-Shell-API-and-C
            byte[]     emptyzip = new byte[] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            var        path     = Path.Combine(basepath, zipName + ".zip");
            FileStream fs       = File.Create(path);

            fs.Write(emptyzip, 0, emptyzip.Length);
            fs.Flush();
            fs.Close();
            fs = null;
            Shell32.ShellClass  sc        = new Shell32.ShellClass();
            Shell32.Folder      SrcFlder  = sc.NameSpace(d.FullName);
            Shell32.Folder      DestFlder = sc.NameSpace(path);
            Shell32.FolderItems items     = SrcFlder.Items();
            DestFlder.CopyHere(items, 20);

            // TODO: FIXME: stop waiting for explorer to finish zipping
            do
            {
                System.Threading.Thread.Sleep(260);
            } while (new FileInfo(path).Length < 2 * 1024);

            if (zipExt != "zip")
            {
                File.Copy(path, Path.Combine(basepath, zipName + zipExt));
                File.Delete(path);
            }

            return(Path.Combine(basepath, zipName + zipExt));
        }
예제 #17
0
 public void unzip()
 {
     listbox_info.Items.Add(" ");
     listbox_info.Items.Add("正在解压文件...");
     try
     {
         Shell32.ShellClass  sc         = new Shell32.ShellClass();
         Shell32.Folder      SrcFolder  = sc.NameSpace(filename);
         Shell32.Folder      DestFolder = sc.NameSpace(Application.StartupPath + "\\");
         Shell32.FolderItems items      = SrcFolder.Items();
         DestFolder.CopyHere(items, 20);
         listbox_info.Items.Add("解压完成...");
     }
     catch (Exception)
     {
         listbox_info.Items.Add("解压失败...");
     }
 }
        static IEnumerable <string> GetItensSelecionadosExplorer(TipoComandoEnum tipoComando)
        {
            // get the active window
            IntPtr handle = NativeMethods.GetForegroundWindow();

            string filename;

            List <Tuple <string, bool> > lstItens = new List <Tuple <string, bool> >();

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindows();
            foreach (SHDocVw.InternetExplorer window in shellWindows)
            {
                // match active window
                if (window.HWND != (int)handle)
                {
                    continue;
                }

                filename = Path.GetFileNameWithoutExtension(window.FullName).ToLower();
                if (filename.ToLowerInvariant() == "explorer")
                {
                    Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                    foreach (Shell32.FolderItem item in items)
                    {
                        lstItens.Add(Tuple.Create(item.Path, item.IsFolder));
                        //bool isArquivo = File.Exists(item.Path);

                        //if (tipoComando == TipoComandoEnum.ArquivoCopiarNomeArquivo)
                        //{
                        //  if (isArquivo)
                        //    lstItens.Add(item.Path);
                        //}
                        //else if (item.IsFolder)
                        //  lstItens.Add(item.Path);
                    }
                }
                else
                {
                    Trace.WriteLine("Não achei janela do explorer");
                }
            }
            return(lstItens.OrderByDescending(x => x.Item2).ThenBy(x => x.Item1).Select(x => x.Item1));
        }
예제 #19
0
 public void ZipFolder(string sourceFolder, string dstFile)
 {
     byte[] emptyzip = new byte[] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
     try
     {
         FileStream fs = File.Create(dstFile);
         fs.Write(emptyzip, 0, emptyzip.Length);
         fs.Flush();
         fs.Close();
         fs = null;
         Shell32.Shell       sc        = new Shell32.Shell();
         Shell32.Folder      SrcFlder  = sc.NameSpace(sourceFolder);
         Shell32.Folder      DestFlder = sc.NameSpace(dstFile);
         Shell32.FolderItems items     = SrcFlder.Items();
         DestFlder.CopyHere(items, 20);
     }
     catch
     {
     }
 }
예제 #20
0
        private bool IsFileOrFolderSelected()
        {
            IntPtr handle = User32Interop.GetForegroundWindow();

            var shell = new Shell32.Shell();

            foreach (SHDocVw.InternetExplorer window in shell.Windows())
            {
                if (window.HWND == (int)handle)
                {
                    Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                    if (items.Count > 0)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
예제 #21
0
        public string[] GetWExplorerSelectedContent(IntPtr hWnd)
        {
            List <string> files = new List <string>();

            SHDocVw.InternetExplorer ie = GetWindowsExplorer(hWnd);
            if (ie != null)
            {
                string class_name = GetClassName(hWnd);
                if (class_name == "CabinetWClass" || class_name == "ExploreWClass")
                {
                    Shell32.IShellFolderViewDual2 folderView = ie.Document as Shell32.IShellFolderViewDual2;
                    Shell32.FolderItems           items      = folderView.SelectedItems();
                    foreach (Shell32.FolderItem item in items)
                    {
                        files.Add(item.Path);
                    }
                }
            }
            return(files.ToArray());
        }
예제 #22
0
        //private void TimeElapsed(object sender, System.Timers.ElapsedEventArgs e)
        //{
        //    selectedFiles = GetSelectedFiles();
        //}

        private static List <string> GetSelectedFiles()
        {
            IntPtr handle = Win32.GetForegroundWindow();

            List <string> selected = new List <string>();
            var           shell    = new Shell32.Shell();

            foreach (SHDocVw.InternetExplorer window in shell.Windows())
            {
                if (window.HWND == (int)handle)
                {
                    Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                    foreach (Shell32.FolderItem item in items)
                    {
                        selected.Add(item.Path);
                    }
                }
            }
            return(selected);
        }
예제 #23
0
        public static IList <string> GetSelectedFilesFromWindow(IntPtr hwnd)
        {
            var fileNames    = new List <string>();
            var shellAppType = Type.GetTypeFromProgID("Shell.Application");
            var shellObject  = Activator.CreateInstance(shellAppType);
            var shellWindows = (SHDocVw.ShellWindows)shellAppType.InvokeMember("Windows", BindingFlags.InvokeMethod, null, shellObject, new object[] { });

            foreach (SHDocVw.InternetExplorer window in shellWindows)
            {
                if (window.HWND == hwnd.ToInt32())
                {
                    var fileName = Path.GetFileNameWithoutExtension(window.FullName).ToLower();
                    if (fileName.ToLowerInvariant() == "explorer")
                    {
                        Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                        fileNames = items.Cast <Shell32.FolderItem>().Select(x => x.Path).ToList();
                    }
                }
            }
            return(fileNames);
        }
예제 #24
0
        /// <summary>
        /// From http://www.fluxbytes.com/csharp/unzipping-files-using-shell32-in-c/ but with
        /// args packed in object array so can be called from new STA Thread in UnZipFromMTAThread().
        /// </summary>
        /// <param name="param">object array containing: [string zipFile, string destinationFolderPath]</param>
        private static void UnZip(string zipFile, string folderPath)
        {
            if (!File.Exists(zipFile))
            {
                throw new FileNotFoundException();
            }

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }

            Shell32.Shell       objShell          = new Shell32.Shell();
            Shell32.Folder      destinationFolder = objShell.NameSpace(folderPath);
            Shell32.Folder      sourceFile        = objShell.NameSpace(zipFile);
            Shell32.FolderItems items             = sourceFile.Items();
            // Flags are: No progress displayed, Respond with 'Yes to All' for any dialog, no UI on error
            // I added 1024 although not sure it's relevant with Zip files.
            // See https://msdn.microsoft.com/en-us/library/windows/desktop/bb787866%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
            destinationFolder.CopyHere(items, 4 | 16 | 1024);
        }
예제 #25
0
        private static Shell32.FolderItem ReadFileInfo()
        {
            IntPtr handle = GetForegroundWindow();

            List <string> selected = new List <string>();

            SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();

            foreach (SHDocVw.ShellBrowserWindow window in shellWindows)
            {
                if (window.HWND == (int)handle)
                {
                    Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                    if (items.Count == 1)
                    {
                        return(items.Item(0));
                    }
                }
            }
            return(null);
        }
예제 #26
0
파일: main.cs 프로젝트: spugnoid/OBBLM-HBBA
        private static int RecurseCount(Shell32.FolderItems Source)
        {
            int ItemCount = 0;

            foreach (Shell32.FolderItem item in Source)
            {
                if (item.IsFolder == true)
                {
                    //Add one for this folder
                    ItemCount++;
                    //Then continue walking down the folder tree
                    ItemCount += RecurseCount(((Shell32.Folder)item.GetFolder).Items());
                }
                else
                {
                    //Add one for this file
                    ItemCount++;
                }
            }

            return(ItemCount);
        }
예제 #27
0
        private static void AddRootNode(TreeView tree, ref int imageCount, ImageList imageList, ShellFolder shellFolder, bool getIcons)
        {
            Shell32.Shell       shell32       = new Shell32.ShellClass();
            Shell32.Folder      shell32Folder = shell32.NameSpace(shellFolder);
            Shell32.FolderItems items         = shell32Folder.Items();

            tree.Nodes.Clear();
            TreeNode desktop = new TreeNode("Desktop", 0, 0);

            // Added in version 1.11
            // add a FolderItem object to the root (Desktop) node tag that corresponds to the DesktopDirectory namespace
            // This ensures that the GetSelectedNodePath will return the actual Desktop folder path when queried.
            // There's possibly a better way to create a Shell32.FolderItem instance for this purpose,
            // but I surely don't know it

            Shell32.Folder dfolder = shell32.NameSpace(ShellFolder.DesktopDirectory);
            foreach (Shell32.FolderItem fi in dfolder.ParentFolder.Items())
            {
                if (fi.Name == dfolder.Title)
                {
                    desktop.Tag = fi;
                    break;
                }
            }

            // Add the Desktop root node to the tree
            tree.Nodes.Add(desktop);

            // iterate through the Desktop namespace and populate the first level nodes
            foreach (Shell32.FolderItem item in items)
            {
                if (item.IsFolder)                // this ensures that desktop shortcuts etc are not displayed
                {
                    TreeNode tn = AddTreeNode(item, ref imageCount, imageList, getIcons);
                    desktop.Nodes.Add(tn);
                    CheckForSubDirs(tn, imageList);
                }
            }
        }
예제 #28
0
        private static void UnzipFileToFolderWindows(string zipFilePath, string destinationFolder)
        {
            const bool showProgress = false;
            const bool yesToAll     = true;

            Shell32.Folder fromFolder = GetShell32NameSpace(zipFilePath);
            Directory.CreateDirectory(destinationFolder);
            Shell32.Folder      toFolder          = GetShell32NameSpace(destinationFolder);
            Shell32.FolderItems sourceFolderItems = fromFolder.Items();

            Shell32.FolderItems itemsToExtract;

            //if the zip file contains a single directory, extract that directory's contents
            if ((sourceFolderItems.Count == 1) &&
                (sourceFolderItems.Item(0).GetFolder is Shell32.Folder))
            {
                Shell32.FolderItem rootItem = sourceFolderItems.Item(0);
                itemsToExtract = ((Shell32.Folder)rootItem.GetFolder).Items();
            }
            else
            {
                itemsToExtract = sourceFolderItems;
            }

            int options = 0;

            if (!showProgress)
            {
                options += 4;
            }
            if (yesToAll)
            {
                options += 16;
            }

            toFolder.CopyHere(itemsToExtract, options);
        }
예제 #29
0
        static void Main(string[] args)
        {
            IntPtr        handle   = GetForegroundWindow();
            List <string> selected = new List <string>();

            Shell32.Shell shell = new Shell32.Shell();

            foreach (var window in shell.Windows())
            {
                var testy  = window.HWND;
                var testy2 = (int)handle;
                if (window.HWND == (int)handle)
                {
                    Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                    foreach (Shell32.FolderItem item in items)
                    {
                        if (args[0] == "browse")
                        {
                            if (item.Path[1] == ':')
                            {
                                String s = String.Format("/select,\"{0}\"", item.Path);

                                shell.ShellExecute("explorer.exe", s);
                            }
                            else
                            {
                                shell.Explore(Path.GetDirectoryName(item.Path));
                            }
                        }
                        if (args[0] == "open")
                        {
                            shell.ShellExecute(args[1], item.Path);
                        }
                    }
                }
            }
        }
예제 #30
0
        private static void Move(string dest)
        {
            IntPtr handle = GetForegroundWindow();

            List <string> selected = new List <string>();
            var           shell    = new Shell32.Shell();

            foreach (SHDocVw.InternetExplorer window in shell.Windows())
            {
                if (window.HWND == (int)handle)
                {
                    Shell32.FolderItems items = ((Shell32.IShellFolderViewDual2)window.Document).SelectedItems();
                    foreach (Shell32.FolderItem item in items)
                    {
                        selected.Add(item.Path);
                        AccessSQL.AccessHandler.Viesti(item.Path);
                    }
                }
            }
            foreach (string path in selected)
            {
                File.Move(path, dest + "\\" + Path.GetFileName(path));
            }
        }