Click here to Skip to main content
15,867,686 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i am using msdev editor for my c++ programing..


i have one vb script.. But i want to do same operation using my c++ program..

if any one explain me how..


VB
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("c:\dmmm\df\*")




how to write the same coding in c++
Posted
Updated 11-Oct-11 22:33pm
v2

You can create it by creating a COM object.

Ex.
C++
HRESULT hr;
CComPtr pDisp;
hr = pDisp.CoCreateInstance( L"Scripting.FileSystemObject" );//creates the object
ATLASSERT( SUCCEEDED(hr) );
CComDispatchDriver disDrv( pDisp );
CComVariant funcArg( LPCTSTR(_T("D:\\test.txt")) ), ret( false );
hr = disDrv.Invoke1(L"DeleteFile", &funcArg, &ret );//delete the file
ATLASSERT( SUCCEEDED(hr) );


You need to include <atlbase.h> for this <atlbase.h>
 
Share this answer
 
v4
Comments
@BangIndia 12-Oct-11 8:04am    
CComDispatchDriver disDrv( pDisp );

in that line CComDispatchDriver is undeclare..

what header file i want include
Richard MacCutchan 12-Oct-11 8:25am    
Please format your code blocks correctly, as shown above.
AnamikaBhattacharya 12-Oct-11 8:42am    
include atlbase.h for this
Instead of creating such object, you may use SHFileOperation function[^] for the purpose.
 
Share this answer
 
v2
Simplest solution:

C++
Scripting::IFileSystemPtr fs(__uuidof(Scripting::FileSystemObject));
fs->__DeleteFile(L"c:\\dmmm\\df\\*", _variant_t(false));


Showing a whole simplistic program:

C++
#include <objbase.h>
#include <comutil.h>
#undef GetFreeSpace
 #import <scrrun.dll> auto_rename


int main()
{
    CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);

    try
    {
        Scripting::IFileSystemPtr fs(__uuidof(Scripting::FileSystemObject));
        fs->__DeleteFile(L"c:\\dmmm\\df\\*", _variant_t(false));
    }
    catch (const _com_error&)
    {}

    CoUninitialize();

    return 0;
}
</scrrun.dll></objbase.h>
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900