Hi All,
If you have requirement to copy files from some folder[Target folder] to your specified folder[destination] then usually we use WinApi class CopyFile() method but this method will not work if you sub-folders in your Target folder then it will show error “ClrObject static method invocation error.”.
To resolve this error first we need to check whether the file you are going to copy is a folder or file that we can do by using WINAPI::folderExists().The correct way to do this as below:
public void copy(FilePath _filePath)
{
int firstFileHandle;
Filename filenameCurrent;
FilePath parentDir = @’D:/tmp’;
;
//winApi::setCurrentDirectory(_filePath);
[firstFileHandle,filenameCurrent] = Winapi::findFirstFile(_filePath + ‘/’ + ‘*.*’);
while(filenameCurrent)
{
IF(filenameCurrent != ‘.’ && filenameCurrent != ‘..’)
{
if(WinApi::fileExists(_filePath + ‘/’ + filenameCurrent, false))
winapi::copyFile(_filePath + ‘/’ + filenameCurrent,@’D:/test/’+filenameCurrent,true);
else if(WinAPi::folderExists(filenameCurrent))
{
this.copy(parentDir + ‘/’ + filenameCurrent);
}
}
filenameCurrent = winapi::findNextFile(firstFileHandle);
}
}
_filePath : path where you want to copy files
Note : This code will work only if you create this method in class it will not work in Jobs