0

http://mwinapi.sourceforge.net/のSystemAccessibleObjectを使用して、Windowsエクスプローラーから現在の作業フォルダーで選択したファイルを取得することができました。

拡張子の付いたファイル名を取得したいのですが、「既知のファイルタイプの拡張子を非表示にする」を有効にすると、ファイル名のみが表示されます。私はこのステップで立ち往生しています。

私のコード:

SystemAccessibleObject currentWorkingWindow = SystemAccessibleObject.FromWindow(new SystemWindow(GetForegroundWindow()), AccessibleObjectID.OBJID_WINDOW).Children.Where(c => c.RoleString.Equals("client")).FirstOrDefault();

            if (null != currentWorkingWindow)
            {
                SystemWindow addressBar = currentWorkingWindow.Window.AllDescendantWindows.Where(w => w.ClassName.Equals("ComboBox")).FirstOrDefault();

                if (null != addressBar)
                {
                    string addressBarContent = addressBar.Content.LongDescription;

                    Match m = Regex.Match(addressBarContent, "Address \\[push button\\]\\n[A-Z]: \\n[A-Z]: ([A-Z]:\\\\[^/:*?<>|\"\\r\\n\\t]+)");

                    if (null != m || null != m.Groups[1])
                    {
                        SystemWindow currentListView = currentWorkingWindow.Window.AllDescendantWindows.Where(w => w.ClassName.Equals("SysListView32")).FirstOrDefault();

                        if (null != currentListView)
                        {
                            SystemAccessibleObject currentListViewItems = SystemAccessibleObject.FromWindow(currentListView, AccessibleObjectID.OBJID_WINDOW).Children.Where(c => c.RoleString.Equals("list")).FirstOrDefault();

                            if (null != currentListViewItems)
                            {
                                SystemAccessibleObject[] selectedItems = currentListViewItems.SelectedObjects;

                                string currentWorkingFolderPath = m.Groups[1].Value;

                                if (0 != selectedItems.Count())
                                {
                                    string[] fileNames = currentListView.Content.PropertyList.Select(p => p.Value).ToArray();
                                }
                            }
                        }

                        currentListView = null;
                    }

                    m = null;
                }

                addressBar = null;
            }

            currentWorkingWindow = null;

どんな助けでもいただければ幸いです!

4

2 に答える 2

0

SystemAccessibleObject については何も知りませんが、別の角度からアプローチしてみませんか。ディレクトリとファイル名は拡張子なしでわかっているので、Directory.GetFilesを使用して拡張子付きのファイルを「検索」できます。

foreach (string fileName in fileNames)
{
  string[] matchedFiles = Directory.GetFiles(currentWorkingFolderPath, fileName+"*");
  etc...
}
于 2010-10-13T15:42:26.090 に答える
0

私はまだ完璧な解決策を見つけていませんが、クリップボードを使用することはそれほど悪い考えではありません。

于 2010-11-05T04:34:16.817 に答える