如何在c ++中创建文件系统对象 [英] How to create the file system object in c++
本文介绍了如何在c ++中创建文件系统对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用msdev编辑器进行我的c ++编程..
i有一个vb脚本..但我想做同样的事情使用我的c ++程序操作..
如果有人解释我怎么样...
>
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\*")
如何在c ++中编写相同的编码
how to write the same coding in c++
推荐答案
您可以通过创建COM对象来创建它。
Ex。
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) );
您需要包含< atlbase.h>对于此< atlbase.h>
You need to include <atlbase.h> for this <atlbase.h>
您可以使用SHFileOperation函数 [ ^ ]为此目的。
Instead of creating such object, you may use SHFileOperation function[^] for the purpose.
最简单的解决方案:
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>
这篇关于如何在c ++中创建文件系统对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文