Click here to Skip to main content
12,065,888 members (27,145 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: COM VBA VisualC++
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..


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



how to write the same coding in c++
Posted 11-Oct-11 21:12pm
Edited 11-Oct-11 23:33pm
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You can create it by creating a COM object.

Ex.
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 for this
  Permalink  
v4
Comments
aimdharma 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
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Instead of creating such object, you may use SHFileOperation function[^] for the purpose.
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Simplest solution:

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

Showing a whole simplistic program:

#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>
  Permalink  
v3

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web03 | 2.8.160207.1 | Last Updated 8 Sep 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100