C++ 如何从虚拟设备中获取文件夹和文件名?
C++ how to get folders and files names from virtual device?
如何获取插入电脑的虚拟设备中的所有文件夹和文件名?
在 C++ 中;
我有问题,因为虚拟设备没有像本地磁盘那样的盘符;
路径是这样开始的 "Computer\SUPRA_M727G\Internal storage"
你必须使用Shell接口,即IShellFolder
and IEnumIDList
。
要为 "Internal storage"
文件夹获取 IShellFolder
,您可以:
使用SHGetDesktopFolder()
to get an IShellFolder
for the root of the Shell namespace, then pass the "Computer\SUPRA_M727G\Internal storage"
string to its IShellFolder::ParseDisplayName()
method to get an absolute ITEMIDLIST
that you can pass to its IShellFolder::BindToObject()
方法。
使用 SHParseDisplayName()
or ILCreateFromPath()
to convert the "Computer\SUPRA_M727G\Internal storage"
string into an absolute ITEMIDLIST
that you can pass to SHBindToObject()
并将其 psf
参数设置为 NULL
。
无论哪种方式,一旦你有一个 IShellFolder
作为存储文件夹,你就可以使用它的 IShellFolder::EnumObjects()
method to get an IEnumIDList
for enumerating its files and subfolders. The enumeration will give you a relative ITEMIDLIST
for each item. To retrieve each item's name as a string, pass each ITEMIDLIST
to its IShellFolder::GetDisplayNameOf()
method, and then pass the returned STRRET
to one of the StrRetTo...()
functions (StrRetToBSTR()
, StrRetToBuf()
, or StrRetToStr()
)。
有关详细信息,请参阅 MSDN:
如何获取插入电脑的虚拟设备中的所有文件夹和文件名? 在 C++ 中;
我有问题,因为虚拟设备没有像本地磁盘那样的盘符;
路径是这样开始的 "Computer\SUPRA_M727G\Internal storage"
你必须使用Shell接口,即IShellFolder
and IEnumIDList
。
要为 "Internal storage"
文件夹获取 IShellFolder
,您可以:
使用
SHGetDesktopFolder()
to get anIShellFolder
for the root of the Shell namespace, then pass the"Computer\SUPRA_M727G\Internal storage"
string to itsIShellFolder::ParseDisplayName()
method to get an absoluteITEMIDLIST
that you can pass to itsIShellFolder::BindToObject()
方法。使用
SHParseDisplayName()
orILCreateFromPath()
to convert the"Computer\SUPRA_M727G\Internal storage"
string into an absoluteITEMIDLIST
that you can pass toSHBindToObject()
并将其psf
参数设置为NULL
。
无论哪种方式,一旦你有一个 IShellFolder
作为存储文件夹,你就可以使用它的 IShellFolder::EnumObjects()
method to get an IEnumIDList
for enumerating its files and subfolders. The enumeration will give you a relative ITEMIDLIST
for each item. To retrieve each item's name as a string, pass each ITEMIDLIST
to its IShellFolder::GetDisplayNameOf()
method, and then pass the returned STRRET
to one of the StrRetTo...()
functions (StrRetToBSTR()
, StrRetToBuf()
, or StrRetToStr()
)。
有关详细信息,请参阅 MSDN: