EDN Admin
Well-known member
Hello,
I have the code to unzip the zip file to a folder from internet as below. Can anyone help me how to get the file name of each file in the folder? Thanks.
BSTR source = ::SysAllocString(zipFile); <br/>
BSTR dest = ::SysAllocString(unzipPath);<br/>
<span style="white-spacere <br/>
HRESULT hResult;<br/>
IShellDispatch *pISD;<br/>
Folder *pToFolder = NULL;<br/>
VARIANT vDir, vFile, vOpt;<br/>
<br/>
CoInitialize(NULL);<br/>
<br/>
hResult = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&pISD);<br/>
<br/>
if (SUCCEEDED(hResult))<br/>
{<br/>
VariantInit(&vDir);<br/>
vDir.vt = VT_BSTR;<br/>
vDir.bstrVal = dest;<br/>
hResult = pISD->NameSpace(vDir, &pToFolder);<br/>
<br/>
if (SUCCEEDED(hResult))<br/>
{<br/>
Folder *pFromFolder = NULL;<br/>
<span style="white-spacere <br/>
<span style="white-spacere VariantInit(&vFile);<br/>
vFile.vt = VT_BSTR;<br/>
vFile.bstrVal = source;<br/>
<span style="white-spacere pISD->NameSpace(vFile, &pFromFolder);<br/>
<span style="white-spacere FolderItems *fi = NULL;<br/>
<span style="white-spacere pFromFolder->Items(&fi);<br/>
<span style="white-spacere long count=0;<br/>
<span style="white-spacere fi->get_Count(&count);<br/>
<span style="white-spacere <span style="white-spacere <br/>
VariantInit(&vOpt);<br/>
vOpt.vt = VT_I4;<br/>
vOpt.lVal = FOF_NO_UI;//4; // Do not display a progress dialog box<br/>
<br/>
<span style="white-spacere // Creating a new Variant with pointer to FolderItems to be copied<br/>
<span style="white-spacere VARIANT newV;<br/>
<span style="white-spacere VariantInit(&newV);<br/>
<span style="white-spacere newV.vt = VT_DISPATCH;<br/>
<span style="white-spacere newV.pdispVal = fi;<br/>
<span style="white-spacere hResult = pToFolder->CopyHere(newV, vOpt);<br/>
<span style="white-spacere pFromFolder->Release();<br/>
pToFolder->Release();<br/>
}<br/>
pISD->Release();<br/>
}<br/>
CoUninitialize();
View the full article
I have the code to unzip the zip file to a folder from internet as below. Can anyone help me how to get the file name of each file in the folder? Thanks.
BSTR source = ::SysAllocString(zipFile); <br/>
BSTR dest = ::SysAllocString(unzipPath);<br/>
<span style="white-spacere <br/>
HRESULT hResult;<br/>
IShellDispatch *pISD;<br/>
Folder *pToFolder = NULL;<br/>
VARIANT vDir, vFile, vOpt;<br/>
<br/>
CoInitialize(NULL);<br/>
<br/>
hResult = CoCreateInstance(CLSID_Shell, NULL, CLSCTX_INPROC_SERVER, IID_IShellDispatch, (void **)&pISD);<br/>
<br/>
if (SUCCEEDED(hResult))<br/>
{<br/>
VariantInit(&vDir);<br/>
vDir.vt = VT_BSTR;<br/>
vDir.bstrVal = dest;<br/>
hResult = pISD->NameSpace(vDir, &pToFolder);<br/>
<br/>
if (SUCCEEDED(hResult))<br/>
{<br/>
Folder *pFromFolder = NULL;<br/>
<span style="white-spacere <br/>
<span style="white-spacere VariantInit(&vFile);<br/>
vFile.vt = VT_BSTR;<br/>
vFile.bstrVal = source;<br/>
<span style="white-spacere pISD->NameSpace(vFile, &pFromFolder);<br/>
<span style="white-spacere FolderItems *fi = NULL;<br/>
<span style="white-spacere pFromFolder->Items(&fi);<br/>
<span style="white-spacere long count=0;<br/>
<span style="white-spacere fi->get_Count(&count);<br/>
<span style="white-spacere <span style="white-spacere <br/>
VariantInit(&vOpt);<br/>
vOpt.vt = VT_I4;<br/>
vOpt.lVal = FOF_NO_UI;//4; // Do not display a progress dialog box<br/>
<br/>
<span style="white-spacere // Creating a new Variant with pointer to FolderItems to be copied<br/>
<span style="white-spacere VARIANT newV;<br/>
<span style="white-spacere VariantInit(&newV);<br/>
<span style="white-spacere newV.vt = VT_DISPATCH;<br/>
<span style="white-spacere newV.pdispVal = fi;<br/>
<span style="white-spacere hResult = pToFolder->CopyHere(newV, vOpt);<br/>
<span style="white-spacere pFromFolder->Release();<br/>
pToFolder->Release();<br/>
}<br/>
pISD->Release();<br/>
}<br/>
CoUninitialize();
View the full article