[IFileSystem ] Problem using IFileSystem Interface from scrrun.dll

/*

Hi Duds,

I am using IFileSystem Interface from scrrun.dll.
It is easier to use “Scripting.FileSystemObject” in Visual Basic.

However, when srcrun.dll is imported so as to used in VC++ project is gives following
compilation error.

warning C4003: not enough actual parameters for macro ‘GetFreeSpace’

GetFreeSpace falls under category of Obsolete Windows Programming Elements.
These functions are supported only for backward compatibility with the 16-bit Windows API.

To get rid of this problem, you need to undefine GetFreeSpace as #undef GetFreeSpace.
Now code starts compling properly.

Real Problem with this interface is:

void CopyFolder(
[in] BSTR Source,
[in] BSTR Destination,
[in, optional, defaultvalue(-1)] VARIANT_BOOL OverWriteFiles);

When folder already exists CopyFolder API throws exception, even when passing
OverWriteFiles=FALSE.

My objetive is if the destination folder already exists, then copy folder should copy files
that are not present in the destination folder.

Below is source code that I am playing with.

So, How to copy file to folder which might already exists?

Thanks & regards,
Rajesh

*/

#include <atlbase.h>

#undef GetFreeSpace // For warning C4003: not enough actual parameters for macro ‘GetFreeSpace’

#import “scrrun.dll”
using namespace Scripting ;

int MyCopyFolder (char *szSrcPath, char *szDstPath)
{
CoInitialize (NULL) ;

try
{
IFileSystemPtr ifSysPtr ;

ifSysPtr.CreateInstance (__uuidof (FileSystemObject)) ;
ifSysPtr->CopyFolder (szSrcPath, szDstPath, FALSE) ;
}
catch (_com_error e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());

MessageBox (0, (char *)bstrSource, (char *)bstrDescription, MB_ICONINFORMATION) ;
}
catch (…)
{
MessageBox (0, “Error occured while copying file.”, “Copy Folder Demo”, 0) ;
}

CoUninitialize ();

return 1 ;
}

int main ()
{
int nRet = MyCopyFolder (“c:\test”, “c:\test1”) ;

return 0 ;
}</atlbase.h>

Rajesh Nikam wrote:

I am using IFileSystem Interface from scrrun.dll.
It is easier to use “Scripting.FileSystemObject” in Visual Basic.

Real Problem with this interface is:

void CopyFolder(
[in] BSTR Source,
[in] BSTR Destination,
[in, optional, defaultvalue(-1)] VARIANT_BOOL
OverWriteFiles);

When folder already exists CopyFolder API throws exception, even
when passing
OverWriteFiles=FALSE.

My objetive is if the destination folder already exists, then copy
folder should copy files
that are not present in the destination folder.

Below is source code that I am playing with.

So, How to copy file to folder which might already exists?

I suspect you are going to have to do this by hand. For every file in
the source directory (with FindFirstFile), if it does not exist in the
destination directory (perhaps with IFileSystem::FileExists), copy it
yourself (perhaps with IFileSystem::CopyFile).

Is the IFileSystem interface really any easier to use than the raw
APIs? It’s helpful from a scripting language, but I’m not sure it is
from C.

Are you aware that the free robocopy utility can already do this?

Thanks Tim,

I suspect you are going to have to do this by hand. For every file in the source directory (with FindFirstFile), if it does not exist in the destination directory (perhaps with IFileSystem::FileExists), copy it yourself (perhaps with IFileSystem::CopyFile).

As suggested, Using FindFirstFile and copying file on our own is right way to achieve the same, that I am already doing.
What is the use of Scripting component which has api CopyFolder () that copies files from source to destination. It has flag
saying “OverWriteFiles” which will over write file if already exists. If the destination folder already present, this poor fellow gives
exception ;-( and this is highly unexpected.

Is the IFileSystem interface really any easier to use than the raw APIs? It’s helpful from a scripting language, but I’m not sure it is from C.

You may be right, this apis are helpful using from scripting languages, however they should provide fucntionality as it is claming. Dont you think so ?

Are you aware that the free robocopy utility can already do this?

I have not looked robocopy before. It seems to windows tool that helps in copying folders. But I dont want to use third party tools in my application.

Gist: Go with using regular winapis and get the job done.

Best regards,
Rajesh Nikam


----- Original Message -----
From: Tim Roberts
To: Windows System Software Devs Interest List
Sent: Thursday, March 03, 2005 11:02 PM
Subject: Re: [ntdev] [IFileSystem] Problem using IFileSystem Interface from scrrun.dll

Rajesh Nikam wrote:

I am using IFileSystem Interface from scrrun.dll.
It is easier to use “Scripting.FileSystemObject” in Visual Basic.

Real Problem with this interface is:

void CopyFolder(
[in] BSTR Source,
[in] BSTR Destination,
[in, optional, defaultvalue(-1)] VARIANT_BOOL OverWriteFiles);

When folder already exists CopyFolder API throws exception, even when passing
OverWriteFiles=FALSE.

My objetive is if the destination folder already exists, then copy folder should copy files
that are not present in the destination folder.

Below is source code that I am playing with.

So, How to copy file to folder which might already exists?

I suspect you are going to have to do this by hand. For every file in the source directory (with FindFirstFile), if it does not exist in the destination directory (perhaps with IFileSystem::FileExists), copy it yourself (perhaps with IFileSystem::CopyFile).

Is the IFileSystem interface really any easier to use than the raw APIs? It’s helpful from a scripting language, but I’m not sure it is from C.

Are you aware that the free robocopy utility can already do this?


Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@hotmail.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Rajesh Nikam wrote:

As suggested, Using FindFirstFile and copying file on our own is right
way to achieve the same, that I am already doing.
What is the use of Scripting component which has api CopyFolder ()
that copies files from source to destination. It has flag
saying “OverWriteFiles” which will over write file if already exists.
If the destination folder already present, this poor fellow gives
exception ;-( and this is highly unexpected.

I would agree with this. Intuitively, I would have expected that, when
OverWriteFiles is false, it would have copied new files and ignored
existing files, but apparently the developer thought differently from
both of us…

Are you aware that the free robocopy utility can already do this?
I have not looked robocopy before. It seems to windows tool that helps
in copying folders. But I dont want to use third party tools in my
application.

Why not? If someone else has already spent time and money developing
and testing a robust application that does exactly what you want, it is
foolish to discard it out of hand as a potential solution just because
you didn’t develop it.

Goodness, my rant quotient is unusually high today.