Re: vbscript: how to generate a FolderItem2 object from a filename ?

JJ <[email protected]>
Newsgroups alt.comp.os.windows-xp,alt.windows7.general
Organization To protect and to server
Message-ID <[email protected]>
On Sat, 22 Jun 2024 12:14:11 +0200, R.Wieser wrote:
> Hello all,
> 
> I found a smal script which uses the "GetDetailsOf" method of a "Folder3" 
> object to extract some properties of a file.
> 
> The thing is that the "GetDetailsOf" method expects a "FolderItem2" object 
> as its first argument.
> 
> And although the "Folder3" object allows iterating thru its children by 
> which it returns an "FolderItem2" object for each of its entries (files, 
> subfolders), I would like to inspect just a single file.

"GetDetailsOf" is a method of "Folder". It's inherited to "Folder2" and
"Folder3". "Folder" is a base class of "Folder2", and "Folder2" is a base
class of "Folder3". So both "Folder3" is also "Folder2", and "Folder2" is
also "Folder".

"Folder"'s "GetDetailsOf" accepts "FolderItem". Not just "FolderItem2".

> So, I need a method to convert a (full) filename into a "FolderItem2" object 
> (withor-without the aid of a "Folder3" object, which "GetDetailsOf" needs 
> anyway).
> 
> Does what I'm looking for even exists ?  And if so, what does it look like ?

Use "ParseName" method of the "Computer" folder. The folder which shows all
of the drives. e.g.

fullfilepath = "d:\dir\subdir\file.ext"
Set objDlg = WScript.CreateObject("Shell.Application")
Set oCompFolder = objDlg.NameSpace(17)
set oFile = oCompFolder.ParseName(fullfilepath)
set oFolder = oFile.GetFolder
sProperty = oNSFolder.GetDetailsOf(oFile, 16)

Not mentioned by MSDN:
Unless done from the "Computer" or "Network" folders, "ParseName" can only
accept file/folder name without any path (i.e. just the name and extension -
as seen in Explorer).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.